Class Checksums
java.lang.Object
com.marksayson.deletionchecker.checksum.Checksums
Checksum helpers that operate over a region of a buffer without copying it.
-
Method Summary
Modifier and TypeMethodDescriptionstatic longcrc32cWithFieldZeroed(ByteBuffer file, int fieldOffset, int fieldLength) Computes the CRC32C offile's bytes from index 0 to itslimit, as if thefieldLengthbytes starting atfieldOffsetwere zero.
-
Method Details
-
crc32cWithFieldZeroed
Computes the CRC32C offile's bytes from index 0 to itslimit, as if thefieldLengthbytes starting atfieldOffsetwere zero. This is how a file's own checksum field is excluded from the value that will be written into it: the writer hashes with the field zeroed, and verification re-derives the value the same way.The three segments (before the field,
fieldLengthzero bytes, after the field) are streamed in place; the file is never copied.file's position and limit are unchanged.- Parameters:
file- a buffer whose[0, limit)range is the complete filefieldOffset- the index of the first byte to treat as zerofieldLength- the number of bytes to treat as zero- Returns:
- the CRC32C as an unsigned 32-bit value in the low bits of the result
-