Do I really not understand the use of any of the classes CRC32or CheckedInputStreamto calculate the checksum by continuously updating with the last input? When the input is <= 128KiB, a valid CRC32 is generated. Anything greater than 128KiB and the checksum fails. Below is the code I'm working with (using the CRC32and object BufferedInputStream, but the same problem occurs if I use CheckedInputStreamCRC32 to track).
I would appreciate any advice or comments, thanks
private static long calcCRC32() throws IOException {
BufferedInputStream inStream = new BufferedInputStream(System.in);
int BLOCK_SIZE = 128*1024;
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();
}
source
share