Chunker chunker = new FixedChunker(EXACT_CHUNK_SIZE, FixedChunker.DEFAULT_DIGEST_ALG);
// Create chunks
int actualChunkCount = 0;
Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputRandom5MBFile);
Chunk lastChunk = null;
while (chunkEnumeration.hasMoreElements()) {
actualChunkCount++;
lastChunk = chunkEnumeration.nextElement();
// Chunk size & checksum
assertEquals("Chunk does not have the expected size.", EXPECTED_CHUNK_SIZE, lastChunk.getSize());
assertNotNull("Chunk checksum should not be null.", lastChunk.getChecksum());
outputCopyOfRandom5MBFileOutputStream.write(lastChunk.getContent());
}
outputCopyOfRandom5MBFileOutputStream.close();
// Number of chunks
assertEquals("Unexpected number of chunks when chunking", EXPECTED_NUMBER_OF_CHUNKS, actualChunkCount);
// Checksums
byte[] inputFileChecksum = FileUtil.createChecksum(inputRandom5MBFile, FixedChunker.DEFAULT_DIGEST_ALG);
byte[] outputFileChecksum = FileUtil.createChecksum(outputCopyOfRandom5MBFile, FixedChunker.DEFAULT_DIGEST_ALG);
assertArrayEquals("Checksums of input and output file do not match.", inputFileChecksum, outputFileChecksum);
assertArrayEquals("Last chunk's getFileChecksum() should be the file checksum.", inputFileChecksum, lastChunk.getFileChecksum());
}