public class AbstractChecksumProvider extends Object implements ChecksumProvider
ChecksumProvider
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 (a HashFunction
instance) as the constructor
parameter.Modifier | Constructor and Description |
---|---|
protected |
AbstractChecksumProvider(com.google.common.hash.HashFunction hashFunction)
Protected ctor.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
checksumAsBytes()
Returns a byte array representation of the calculated checksum.
|
String |
checksumAsString()
Returns a
String 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(ByteBuffer byteBuffer)
Updates the internal checksum value with data from a byte buffer.
|
ChecksumProvider |
putFile(String filePath)
Updates the internal checksum value with data from a file identified by a
path.
|
protected AbstractChecksumProvider(com.google.common.hash.HashFunction hashFunction)
hashFunction
- public ChecksumProvider putBytes(byte[] byteArray)
ChecksumProvider
putBytes
in interface ChecksumProvider
byteArray
- The input byte array.ChecksumProvider.putBytes(byte[])
public ChecksumProvider putBytes(byte[] byteArray, int offset, int length)
ChecksumProvider
byteArray[offset]
, last byte read
is byteArray[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.putBytes
in interface ChecksumProvider
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.ChecksumProvider.putBytes(byte[], int, int)
public ChecksumProvider putBytes(ByteBuffer byteBuffer)
ChecksumProvider
putBytes
in interface ChecksumProvider
byteBuffer
- The input byte buffer.ChecksumProvider.putBytes(ByteBuffer)
public ChecksumProvider putFile(String filePath)
ChecksumProvider
putFile
in interface ChecksumProvider
filePath
- String
representing the absolute file path.ChecksumProvider.putFile(String)
public byte[] checksumAsBytes()
ChecksumProvider
put*
) will cause it to throw IllegalStateException.checksumAsBytes
in interface ChecksumProvider
byte[]
The checksum in a byte array.ChecksumProvider.checksumAsBytes()
public String checksumAsString()
ChecksumProvider
String
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.checksumAsString
in interface ChecksumProvider
String
The hexadecimal value of the checksum.ChecksumProvider.checksumAsString()
Version: 5.3.3-ice35-b63
Copyright © 2017 The University of Dundee & Open Microscopy Environment. All Rights Reserved.