Package com.scurrilous.circe.impl
Class AbstractStatefulHash
- java.lang.Object
-
- com.scurrilous.circe.impl.AbstractStatefulHash
-
- All Implemented Interfaces:
Hash,StatefulHash
- Direct Known Subclasses:
IncrementalIntStatefulHash,IncrementalLongStatefulHash,JavaCrc32
public abstract class AbstractStatefulHash extends java.lang.Object implements StatefulHash
Base implementation for stateful hash functions.
-
-
Constructor Summary
Constructors Constructor Description AbstractStatefulHash()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description bytegetByte()Returns the first byte of the output of this hash function.byte[]getBytes()Returns a new byte array containing the output of this hash function.intgetBytes(byte[] output, int index, int maxLength)Writes the output of this hash function into the given byte array at the given offset.shortgetShort()Returns the first two bytes of the output of this hash function as a little-endianshort.booleansupportsUnsafe()Returns whether this hash function supports unsafe access to arbitrary memory addresses using methods such asStatefulHash.update(long, long),StatelessIntHash.calculate(long, long), orIncrementalIntHash.resume(int, long, long).voidupdate(byte[] input)Updates the state of this hash function with the entire given input array.voidupdate(byte[] input, int index, int length)Updates the state of this hash function with the given range of the given input array.voidupdate(long address, long length)Updates the state of this hash function with memory with the given address and length.voidupdate(java.nio.ByteBuffer input)Updates the state of this hash function with the remaining contents of the given input buffer.protected abstract voidupdateUnchecked(byte[] input, int index, int length)Updates the state of this hash function with the given range of the given input array.protected voidwriteBytes(byte[] output, int index, int length)Writes the output of this hash function into the given range of the given byte array.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.scurrilous.circe.StatefulHash
createNew, getInt, getLong, reset, supportsIncremental
-
-
-
-
Method Detail
-
supportsUnsafe
public boolean supportsUnsafe()
Description copied from interface:HashReturns whether this hash function supports unsafe access to arbitrary memory addresses using methods such asStatefulHash.update(long, long),StatelessIntHash.calculate(long, long), orIncrementalIntHash.resume(int, long, long). Such functions are generally implemented in native code.- Specified by:
supportsUnsafein interfaceHash- Returns:
- true if unsafe access is supported, false if not
-
update
public void update(byte[] input)
Description copied from interface:StatefulHashUpdates the state of this hash function with the entire given input array.- Specified by:
updatein interfaceStatefulHash- Parameters:
input- the input array
-
update
public void update(byte[] input, int index, int length)Description copied from interface:StatefulHashUpdates the state of this hash function with the given range of the given input array.- Specified by:
updatein interfaceStatefulHash- Parameters:
input- the input arrayindex- the starting index of the first input bytelength- the length of the input range
-
update
public void update(java.nio.ByteBuffer input)
Description copied from interface:StatefulHashUpdates the state of this hash function with the remaining contents of the given input buffer. This method leaves the buffer position at the limit.- Specified by:
updatein interfaceStatefulHash- Parameters:
input- the input buffer
-
update
public void update(long address, long length)Description copied from interface:StatefulHashUpdates the state of this hash function with memory with the given address and length. The arguments are generally not checked in any way and will likely lead to a VM crash or undefined results if invalid.- Specified by:
updatein interfaceStatefulHash- Parameters:
address- the base address of the inputlength- the length of the input- See Also:
Hash.supportsUnsafe()
-
updateUnchecked
protected abstract void updateUnchecked(byte[] input, int index, int length)Updates the state of this hash function with the given range of the given input array. The index and length parameters have already been validated.- Parameters:
input- the input arrayindex- the starting index of the first input bytelength- the length of the input range
-
getBytes
public byte[] getBytes()
Description copied from interface:StatefulHashReturns a new byte array containing the output of this hash function. The caller may freely modify the contents of the array.- Specified by:
getBytesin interfaceStatefulHash- Returns:
- a new byte array containing the hash output
-
getBytes
public int getBytes(byte[] output, int index, int maxLength)Description copied from interface:StatefulHashWrites the output of this hash function into the given byte array at the given offset.- Specified by:
getBytesin interfaceStatefulHash- Parameters:
output- the destination array for the outputindex- the starting index of the first output bytemaxLength- the maximum number of bytes to write- Returns:
- the number of bytes written
-
writeBytes
protected void writeBytes(byte[] output, int index, int length)Writes the output of this hash function into the given range of the given byte array. The inputs have already been validated.- Parameters:
output- the destination array for the outputindex- the starting index of the first output bytelength- the number of bytes to write
-
getByte
public byte getByte()
Description copied from interface:StatefulHashReturns the first byte of the output of this hash function.- Specified by:
getBytein interfaceStatefulHash- Returns:
- the first output byte
-
getShort
public short getShort()
Description copied from interface:StatefulHashReturns the first two bytes of the output of this hash function as a little-endianshort. If the output is less than two bytes, the remaining bytes are set to 0.- Specified by:
getShortin interfaceStatefulHash- Returns:
- the first two output bytes as a short
-
-