@Test public void testGetNowLocalFileList() throws IOException { Map<String, Set<String>> allFileList = new HashMap<>(); Map<String, Set<String>> fileList = new HashMap<>(); manager.getNowLocalFileList(new String[]{SENDER_FILE_PATH_TEST}); fileList = manager.getNowLocalFiles(); assert (isEmpty(fileList)); Random r = new Random(0); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { if (!allFileList.containsKey(String.valueOf(i))) { allFileList.put(String.valueOf(i), new HashSet<>()); } String rand = String.valueOf(r.nextInt(10000)); String fileName = SENDER_FILE_PATH_TEST + File.separator + String.valueOf(i) + File.separator + rand; File file = new File(fileName); allFileList.get(String.valueOf(i)).add(file.getAbsolutePath()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } if (!file.exists()) { file.createNewFile(); } } } manager.getNowLocalFileList(new String[]{SENDER_FILE_PATH_TEST}); fileList = manager.getNowLocalFiles(); assert (allFileList.size() == fileList.size()); for (Entry<String, Set<String>> entry : fileList.entrySet()) { assert (allFileList.containsKey(entry.getKey())); assert (allFileList.get(entry.getKey()).containsAll(entry.getValue())); } int count = 0; Map<String, Set<String>> deleteFile = new HashMap<>(); for (Entry<String, Set<String>> entry : allFileList.entrySet()) { deleteFile.put(entry.getKey(), new HashSet<>()); for (String path : entry.getValue()) { count++; if (count % 3 == 0) { deleteFile.get(entry.getKey()).add(path); } } } for (Entry<String, Set<String>> entry : deleteFile.entrySet()) { for (String path : entry.getValue()) { new File(path).delete(); allFileList.get(entry.getKey()).remove(path); } } r = new Random(1); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { if (!allFileList.containsKey(String.valueOf(i))) { allFileList.put(String.valueOf(i), new HashSet<>()); } String rand = String.valueOf(r.nextInt(10000)); String fileName = SENDER_FILE_PATH_TEST + File.separator + String.valueOf(i) + File.separator + rand; File file = new File(fileName); allFileList.get(String.valueOf(i)).add(file.getAbsolutePath()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } if (!file.exists()) { file.createNewFile(); } } } manager.setNowLocalFiles(new HashMap<>()); manager.getNowLocalFileList(new String[]{SENDER_FILE_PATH_TEST}); fileList = manager.getNowLocalFiles(); assert (allFileList.size() == fileList.size()); for (Entry<String, Set<String>> entry : fileList.entrySet()) { assert (allFileList.containsKey(entry.getKey())); System.out.println("allFileList"); for (String a : allFileList.get(entry.getKey())) { System.out.println(a); } System.out.println("FileList"); for (String a : entry.getValue()) { System.out.println(a); } assert (allFileList.get(entry.getKey()).containsAll(entry.getValue())); } }
public void getNowLocalFileList(String[] paths) { for (String path : paths) { if (!new File(path).exists()) { continue; } File[] listFiles = new File(path).listFiles(); for (File storageGroup : listFiles) { if (storageGroup.isDirectory() && !storageGroup.getName().equals("postback")) { if (!nowLocalFiles.containsKey(storageGroup.getName())) { nowLocalFiles.put(storageGroup.getName(), new HashSet<String>()); } if (!sendingFiles.containsKey(storageGroup.getName())) { sendingFiles.put(storageGroup.getName(), new HashSet<String>()); } File[] files = storageGroup.listFiles(); for (File file : files) { if (!file.getAbsolutePath().endsWith(".restore")) { if (!new File(file.getAbsolutePath() + ".restore").exists()) { nowLocalFiles.get(storageGroup.getName()).add(file.getAbsolutePath()); } } } } } } }
FileManager { public void getNowLocalFileList(String[] paths) { for (String path : paths) { if (!new File(path).exists()) { continue; } File[] listFiles = new File(path).listFiles(); for (File storageGroup : listFiles) { if (storageGroup.isDirectory() && !storageGroup.getName().equals("postback")) { if (!nowLocalFiles.containsKey(storageGroup.getName())) { nowLocalFiles.put(storageGroup.getName(), new HashSet<String>()); } if (!sendingFiles.containsKey(storageGroup.getName())) { sendingFiles.put(storageGroup.getName(), new HashSet<String>()); } File[] files = storageGroup.listFiles(); for (File file : files) { if (!file.getAbsolutePath().endsWith(".restore")) { if (!new File(file.getAbsolutePath() + ".restore").exists()) { nowLocalFiles.get(storageGroup.getName()).add(file.getAbsolutePath()); } } } } } } } }
FileManager { public void getNowLocalFileList(String[] paths) { for (String path : paths) { if (!new File(path).exists()) { continue; } File[] listFiles = new File(path).listFiles(); for (File storageGroup : listFiles) { if (storageGroup.isDirectory() && !storageGroup.getName().equals("postback")) { if (!nowLocalFiles.containsKey(storageGroup.getName())) { nowLocalFiles.put(storageGroup.getName(), new HashSet<String>()); } if (!sendingFiles.containsKey(storageGroup.getName())) { sendingFiles.put(storageGroup.getName(), new HashSet<String>()); } File[] files = storageGroup.listFiles(); for (File file : files) { if (!file.getAbsolutePath().endsWith(".restore")) { if (!new File(file.getAbsolutePath() + ".restore").exists()) { nowLocalFiles.get(storageGroup.getName()).add(file.getAbsolutePath()); } } } } } } } private  FileManager(); }
FileManager { public void getNowLocalFileList(String[] paths) { for (String path : paths) { if (!new File(path).exists()) { continue; } File[] listFiles = new File(path).listFiles(); for (File storageGroup : listFiles) { if (storageGroup.isDirectory() && !storageGroup.getName().equals("postback")) { if (!nowLocalFiles.containsKey(storageGroup.getName())) { nowLocalFiles.put(storageGroup.getName(), new HashSet<String>()); } if (!sendingFiles.containsKey(storageGroup.getName())) { sendingFiles.put(storageGroup.getName(), new HashSet<String>()); } File[] files = storageGroup.listFiles(); for (File file : files) { if (!file.getAbsolutePath().endsWith(".restore")) { if (!new File(file.getAbsolutePath() + ".restore").exists()) { nowLocalFiles.get(storageGroup.getName()).add(file.getAbsolutePath()); } } } } } } } private  FileManager(); static final FileManager getInstance(); void init(); void getSendingFileList(); void getLastLocalFileList(String path); void getNowLocalFileList(String[] paths); void backupNowLocalFileInfo(String backupFile); Map<String, Set<String>> getSendingFiles(); Set<String> getLastLocalFiles(); Map<String, Set<String>> getNowLocalFiles(); void setNowLocalFiles(Map<String, Set<String>> newNowLocalFiles); }
FileManager { public void getNowLocalFileList(String[] paths) { for (String path : paths) { if (!new File(path).exists()) { continue; } File[] listFiles = new File(path).listFiles(); for (File storageGroup : listFiles) { if (storageGroup.isDirectory() && !storageGroup.getName().equals("postback")) { if (!nowLocalFiles.containsKey(storageGroup.getName())) { nowLocalFiles.put(storageGroup.getName(), new HashSet<String>()); } if (!sendingFiles.containsKey(storageGroup.getName())) { sendingFiles.put(storageGroup.getName(), new HashSet<String>()); } File[] files = storageGroup.listFiles(); for (File file : files) { if (!file.getAbsolutePath().endsWith(".restore")) { if (!new File(file.getAbsolutePath() + ".restore").exists()) { nowLocalFiles.get(storageGroup.getName()).add(file.getAbsolutePath()); } } } } } } } private  FileManager(); static final FileManager getInstance(); void init(); void getSendingFileList(); void getLastLocalFileList(String path); void getNowLocalFileList(String[] paths); void backupNowLocalFileInfo(String backupFile); Map<String, Set<String>> getSendingFiles(); Set<String> getLastLocalFiles(); Map<String, Set<String>> getNowLocalFiles(); void setNowLocalFiles(Map<String, Set<String>> newNowLocalFiles);  }