One thing to bear in mind is that the checksum you output is cumulative -- if you used 'testtesttest' as a string and the size of the array would be 4, all three checksums would be different.
This is because CheckedInputStream is not resetting the checksum after it is calculated.
If you want to generate 'consistent' checksums, then instead of using unreferenced value of the checksum scheme in the CIS constructor:
CheckedInputStream cis = new CheckedInputStream(bais, new Adler32());
use:
Checksum checksum = new Adler32();
CheckedInputStream cis = new CheckedInputStream(bais, checksum);
then you can use:
checksum.reset();
in the while loop. I know it's been ages since your post, but I hope it will help other people. and btw, the post was really useful!
checksumMarek January 10, 2012 at 11:04 AM
One thing to bear in mind is that the checksum you output is cumulative -- if you used 'testtesttest' as a string and the size of the array would be 4, all three checksums would be different. This is because CheckedInputStream is not resetting the checksum after it is calculated. If you want to generate 'consistent' checksums, then instead of using unreferenced value of the checksum scheme in the CIS constructor: CheckedInputStream cis = new CheckedInputStream(bais, new Adler32()); use: Checksum checksum = new Adler32(); CheckedInputStream cis = new CheckedInputStream(bais, checksum); then you can use: checksum.reset(); in the while loop. I know it's been ages since your post, but I hope it will help other people. and btw, the post was really useful!
Post your Comment