Java:从流更新CRC32
我是否误解了使用Java:从流更新CRC32,java,crc32,Java,Crc32,我是否误解了使用CRC32或CheckedInputStream类通过不断更新最新输入来计算校验和?当输入值为+1时,将大幅减少文本和示例代码。保持这种思维方式。调用crc32.reset真的有必要吗? private static long calcCRC32() throws IOException { BufferedInputStream inStream = new BufferedInputStream(System.in); int BLOCK_SIZE = 128
CRC32
或CheckedInputStream
类通过不断更新最新输入来计算校验和?当输入值为+1时,将大幅减少文本和示例代码。保持这种思维方式。调用crc32.reset
真的有必要吗?
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();
}