Created
July 11, 2016 08:06
-
-
Save hacksoldier/07065a3d9dd7f18a553200b7ef026be2 to your computer and use it in GitHub Desktop.
Check files for checksum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void checkFilesForChecksum(List<File> files1, List<File> files2) | |
{ | |
Map<String, File> files2Map = new TreeMap<String, File>(); | |
files2.stream().filter(p -> p.isFile()).forEach(p -> files2Map.put(checksum(p), p)); | |
files1.forEach(file -> { | |
if (file.isDirectory()) | |
{ | |
Optional<File> opt = files2.stream().filter(p -> file.isDirectory() && p.getName().equals(file.getName())).findFirst(); | |
if (opt.isPresent()) | |
checkFilesForChecksum(Arrays.asList(file.listFiles()), Arrays.asList(opt.get().listFiles())); | |
else | |
FILE.info("Dir:" + file.getName()); | |
} | |
else if (file.isFile()) | |
{ | |
if (!files2Map.containsKey(checksum(file))) | |
FILE.info("File:" + file.getName()); | |
} | |
else | |
{ | |
throw new RuntimeException(file.getName() + " is not a FILE and is not a directory"); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment