Package com.seeq.utilities
Class Checksum
java.lang.Object
com.seeq.utilities.Checksum
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 Summary
ConstructorsConstructorDescriptionChecksum()
Intended to be used in conjunction withaddFile(File)
to checksum a set of files.Checksum
(byte[] bytes) Computes a checksum by hashing a byte array.Computes a checksum for an object by reading from a file.Computes a checksum for an object by reading from a file. -
Method Summary
Modifier and TypeMethodDescriptionaddByteArray
(byte[] bytes) Add a byte array to the checksum computation.Add a file to the checksum computation.Add a path to the checksum computation.Add files to the checksum computation.byte[]
getHash()
Returns a hash byte array representing the checksumtoString()
Returns a hexadecimal string representing the checksum
-
Constructor Details
-
Checksum
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
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 withaddFile(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
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
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
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
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
Returns a hexadecimal string representing the checksum
-