Package ome.util.checksum
Class AbstractChecksumProvider
- java.lang.Object
-
- ome.util.checksum.AbstractChecksumProvider
-
- All Implemented Interfaces:
ChecksumProvider
- Direct Known Subclasses:
Adler32ChecksumProviderImpl
,CRC32ChecksumProviderImpl
,MD5ChecksumProviderImpl
,Murmur128ChecksumProviderImpl
,Murmur32ChecksumProviderImpl
,SHA1ChecksumProviderImpl
public class AbstractChecksumProvider extends java.lang.Object implements ChecksumProvider
Abstract skeleton class implementingChecksumProvider
and providing implementations of the interface methods using a universal checksum class object. Classes extending this class shall pass in a concrete checksum algorithm implementation (aHashFunction
instance) as the constructor parameter.- Since:
- 4.4.7
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractChecksumProvider(com.google.common.hash.HashFunction hashFunction)
Protected constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
checksumAsBytes()
Returns a byte array representation of the calculated checksum.java.lang.String
checksumAsString()
Returns aString
representing the checksum in hex form.ChecksumProvider
putBytes(byte[] byteArray)
Updates the internal checksum value with data from a byte array.ChecksumProvider
putBytes(byte[] byteArray, int offset, int length)
Updates the internal checksum value with data from a chunk of a byte array.ChecksumProvider
putBytes(java.nio.ByteBuffer byteBuffer)
Updates the internal checksum value with data from a byte buffer.ChecksumProvider
putFile(java.lang.String filePath)
Updates the internal checksum value with data from a file identified by a path.
-
-
-
Method Detail
-
putBytes
public ChecksumProvider putBytes(byte[] byteArray)
Description copied from interface:ChecksumProvider
Updates the internal checksum value with data from a byte array. If the array is null, throws NPE. Note that, although checksum results are consistent for any given hash function and byte array, different hash functions may calculate different checksums for an empty array despite its lack of content.- Specified by:
putBytes
in interfaceChecksumProvider
- Parameters:
byteArray
- The input byte array.- Returns:
- ChecksumProvider
- See Also:
ChecksumProvider.putBytes(byte[])
-
putBytes
public ChecksumProvider putBytes(byte[] byteArray, int offset, int length)
Description copied from interface:ChecksumProvider
Updates the internal checksum value with data from a chunk of a byte array. First byte read isbyteArray[offset]
, last byte read isbyteArray[offset + length - 1]
. If the array is null, throws NPE. Throws IOOB if indexes are invalid. Note that, although checksum results are consistent for any given hash function and byte array, different hash functions may calculate different checksums for an empty array despite its lack of content.- Specified by:
putBytes
in interfaceChecksumProvider
- Parameters:
byteArray
- The input byte array.offset
- The offset in the byte array at which to start putting bytes.length
- The number of bytes to put, starting from the offset.- Returns:
- ChecksumProvider
- See Also:
ChecksumProvider.putBytes(byte[], int, int)
-
putBytes
public ChecksumProvider putBytes(java.nio.ByteBuffer byteBuffer)
Description copied from interface:ChecksumProvider
Updates the internal checksum value with data from a byte buffer. If the array underlying the byte buffer is not accessible, throws an IllegalArgumentException.- Specified by:
putBytes
in interfaceChecksumProvider
- Parameters:
byteBuffer
- The input byte buffer.- Returns:
- ChecksumProvider
- See Also:
ChecksumProvider.putBytes(ByteBuffer)
-
putFile
public ChecksumProvider putFile(java.lang.String filePath)
Description copied from interface:ChecksumProvider
Updates the internal checksum value with data from a file identified by a path. Throws a RuntimeException in a case of an IO error. Input previous to this method does not affect the calculated checksum.- Specified by:
putFile
in interfaceChecksumProvider
- Parameters:
filePath
-String
representing the absolute file path.- Returns:
- ChecksumProvider
- See Also:
ChecksumProvider.putFile(String)
-
checksumAsBytes
public byte[] checksumAsBytes()
Description copied from interface:ChecksumProvider
Returns a byte array representation of the calculated checksum. Subsequent calls to this method will return the same object state. After calling this method any invocation of the mutating methods (put*
) will cause it to throw IllegalStateException.- Specified by:
checksumAsBytes
in interfaceChecksumProvider
- Returns:
byte[]
The checksum in a byte array.- See Also:
ChecksumProvider.checksumAsBytes()
-
checksumAsString
public java.lang.String checksumAsString()
Description copied from interface:ChecksumProvider
Returns aString
representing the checksum in hex form. Subsequent calls to this method will return the same object state. After calling this method any invocation of the mutating methods (put*
) will cause it to throw IllegalStateException.- Specified by:
checksumAsString
in interfaceChecksumProvider
- Returns:
String
The hexadecimal value of the checksum.- See Also:
ChecksumProvider.checksumAsString()
-
-