Class Checksums

java.lang.Object
com.marksayson.deletionchecker.checksum.Checksums

public final class Checksums extends Object
Checksum helpers that operate over a region of a buffer without copying it.
  • Method Details

    • crc32cWithFieldZeroed

      public static long crc32cWithFieldZeroed(ByteBuffer file, int fieldOffset, int fieldLength)
      Computes the CRC32C of file's bytes from index 0 to its limit, as if the fieldLength bytes starting at fieldOffset were 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, fieldLength zero 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 file
      fieldOffset - the index of the first byte to treat as zero
      fieldLength - the number of bytes to treat as zero
      Returns:
      the CRC32C as an unsigned 32-bit value in the low bits of the result