Am I misunderstanding the use of either of the CRC32
or CheckedInputStream
classes to calculate a checksum by continuously updating with the latest input? When the input is <= 128KiB a valid CRC32 is generated. Anything larger than 128KiB and the checksum fails. Below is some code I am working with (using a CRC32
object and BufferedInputStream
but the same problem happens if I use a CheckedInputStream
to keep track of the CRC32).
I would appreciate any advice or comments, thank you
private static long calcCRC32() throws IOException {
BufferedInputStream inStream = new BufferedInputStream(System.in);
int BLOCK_SIZE = 128*1024; //128KiB
int len;
byte[] buffer = new byte[BLOCK_SIZE];
CRC32 crc32 = new CRC32();
crc32.reset();
while((len = bufferedInputStream.read(buffer, 0, BLOCK_SIZE)) > 0){
crc32.update(buffer, 0, len);
buffer = new byte[BLOCK_SIZE];
}
return crc32.getValue();
}