Class Checksum

java.lang.Object
com.seeq.utilities.Checksum

public class Checksum extends Object
Provides a method of computing a checksum for both in-memory objects and files. Implements convenient toString() and equals() methods for conversion to a hex representation and for comparison. Note: The checksum is done in a transitive manner. I.e., the order of items added to the checksum does not affect the final checksum value.
  • Constructor Details

    • Checksum

      public Checksum(Path filePath) throws IOException
      Computes a checksum for an object by reading from a file.
      Parameters:
      filePath - the path to create a checksum for
      Throws:
      IOException - thrown if there is an issue reading the file
    • Checksum

      public Checksum(File fileName) throws IOException
      Computes a checksum for an object by reading from a file.
      Parameters:
      fileName - the file to create a checksum for
      Throws:
      IOException - thrown if there is an issue reading the file
    • Checksum

      public Checksum(byte[] bytes)
      Computes a checksum by hashing a byte array.
      Parameters:
      bytes - the bytes to create a checksum for
    • Checksum

      public Checksum()
      Intended to be used in conjunction with addFile(File) to checksum a set of files.
  • Method Details

    • getHash

      public byte[] getHash()
      Returns a hash byte array representing the checksum
      Returns:
      a hash byte array representing the checksum
    • addFile

      public Checksum addFile(Path path) throws IOException
      Add a path to the checksum computation. Useful for computing the checksum of a set of files.
      Parameters:
      path - The file to add to the checksum.
      Returns:
      This object to allow fluent style programming.
      Throws:
      IOException - If a file access error occurs.
    • addFile

      public Checksum addFile(File file) throws IOException
      Add a file to the checksum computation. Useful for computing the checksum of a set of files.
      Parameters:
      file - The file to add to the checksum.
      Returns:
      This object to allow fluent style programming.
      Throws:
      IOException - If a file access error occurs.
    • addFiles

      public Checksum addFiles(Iterator<File> files) throws IOException
      Add files to the checksum computation.
      Parameters:
      files - The files to add to the checksum
      Returns:
      This object to allow fluent style programming.
      Throws:
      IOException - If a file access error occurs.
    • addByteArray

      public Checksum addByteArray(byte[] bytes)
      Add a byte array to the checksum computation.
      Parameters:
      bytes - The bytes to add to the checksum
      Returns:
      This object to allow fluent style programming.
    • toString

      public String toString()
      Returns a hexadecimal string representing the checksum
      Overrides:
      toString in class Object