Java:从流更新CRC32

kav*_*man 5 java crc32

我是否误解了使用任何一个CRC32或多个CheckedInputStream类来通过不断更新最新输入来计算校验和?当输入<= 128KiB时,生成有效的CRC32.任何大于128KiB且校验和失败的东西.下面是我正在使用的一些代码(使用CRC32对象,BufferedInputStream但如果我使用a CheckedInputStream来跟踪CRC32,则会出现同样的问题).

我将不胜感激任何建议或意见,谢谢

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();
}
Run Code Online (Sandbox Code Playgroud)