I have a boolean method of files comparison. It get's part of bb and check out on equal. If parts equal - get next block. If position (point) > file size and all blocks are equal - return true. Works on small files (10MB), but have troubles on big one.
private static boolean getFiles(File file1, File file2) throws IOException {
FileChannel channel1 = new FileInputStream(file1).getChannel();
FileChannel channel2 = new FileInputStream(file2).getChannel();
int SIZE;
MappedByteBuffer buffer1, buffer2;
for (int point = 0; point < channel1.size(); point += SIZE) {
SIZE = (int) Math.min((4096*1024), channel1.size() - point);
buffer1 = channel1.map(FileChannel.MapMode.READ_ONLY, point, SIZE);
buffer2 = channel2.map(FileChannel.MapMode.READ_ONLY, point, SIZE);
if (!buffer1.equals(buffer2)) {
return false;
}
}
return true;
}
How can I modify it? Change the size of blocks?