Class Checksummer

java.lang.Object
edu.harvard.hul.ois.jhove.Checksummer
All Implemented Interfaces:
Checksum

public class Checksummer extends Object implements Checksum
The Checksummer class encapsulates the calculation of the CRC32, MD5, SHA-1 and SHA-256 checksums.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
    Byte count.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a Checksummer, with instances of each of CRC32, MD5, SHA-1 and SHA-256 MessageDigest.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the CRC32 as a hex string.
    Returns the value of the MD5 digest as a hex string.
    Returns the value of the SHA-1 digest as a hex string.
    Returns the value of the SHA-256 digest as a hex string.
    long
    getValue is required by the Checksum interface, but we can return only one of the three values.
    void
    Resets all checksums and the byte count to their initial values.
    void
    update(byte b)
    Updates the checksum with the argument.
    void
    update(byte[] b)
    Updates the checksum with the argument.
    void
    update(byte[] b, int off, int len)
    Updates the checksum with the argument.
    void
    update(int b)
    Updates the checksum with the argument.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.zip.Checksum

    update
  • Field Details

    • _nByte

      protected long _nByte
      Byte count.
  • Constructor Details

    • Checksummer

      public Checksummer()
      Creates a Checksummer, with instances of each of CRC32, MD5, SHA-1 and SHA-256 MessageDigest. If one or both of the MessageDigests aren't supported on the current platform, they are left as null.
      See Also:
  • Method Details

    • reset

      public void reset()
      Resets all checksums and the byte count to their initial values.
      Specified by:
      reset in interface Checksum
    • getValue

      public long getValue()
      getValue is required by the Checksum interface, but we can return only one of the three values. We return the CRC32 value, since that's the one which is guaranteed to be available.
      Specified by:
      getValue in interface Checksum
    • update

      public void update(byte b)
      Updates the checksum with the argument. Called when a signed byte is available.
    • update

      public void update(int b)
      Updates the checksum with the argument. Called when an unsigned byte is available.
      Specified by:
      update in interface Checksum
    • update

      public void update(byte[] b)
      Updates the checksum with the argument. Called when a byte array is available.
      Specified by:
      update in interface Checksum
    • update

      public void update(byte[] b, int off, int len)
      Updates the checksum with the argument. Called when a byte array is available.
      Specified by:
      update in interface Checksum
    • getCRC32

      public String getCRC32()
      Returns the value of the CRC32 as a hex string.
    • getMD5

      public String getMD5()
      Returns the value of the MD5 digest as a hex string. Returns null if the digest is not available.
    • getSHA1

      public String getSHA1()
      Returns the value of the SHA-1 digest as a hex string. Returns null if the digest is not available.
    • getSHA256

      public String getSHA256()
      Returns the value of the SHA-256 digest as a hex string. Returns null if the digest is not available.