in src/main/java/org/apache/commons/io/file/PathUtils.java [635:665]
public static boolean directoryAndFileContentEquals(final Path path1, final Path path2, final LinkOption[] linkOptions, final OpenOption[] openOptions,
final FileVisitOption[] fileVisitOption) throws IOException {
// First walk both file trees and gather normalized paths.
if (path1 == null && path2 == null) {
return true;
}
if (path1 == null || path2 == null) {
return false;
}
if (notExists(path1) && notExists(path2)) {
return true;
}
final RelativeSortedPaths relativeSortedPaths = new RelativeSortedPaths(path1, path2, Integer.MAX_VALUE, linkOptions, fileVisitOption);
// If the normalized path names and counts are not the same, no need to compare contents.
if (!relativeSortedPaths.equals) {
return false;
}
// Both visitors contain the same normalized paths, we can compare file contents.
final List<Path> fileList1 = relativeSortedPaths.relativeFileList1;
final List<Path> fileList2 = relativeSortedPaths.relativeFileList2;
for (final Path path : fileList1) {
final int binarySearch = Collections.binarySearch(fileList2, path);
if (binarySearch <= -1) {
throw new IllegalStateException("Unexpected mismatch.");
}
if (!fileContentEquals(path1.resolve(path), path2.resolve(path), linkOptions, openOptions)) {
return false;
}
}
return true;
}