abstract class AbstractStreamingHasher extends AbstractHasher
Hasher; handles accumulating data until an
entire "chunk" (of implementation-dependent length) is ready to be hashed.| Modifier and Type | Field and Description |
|---|---|
private java.nio.ByteBuffer |
buffer
Buffer via which we pass data to the hash algorithm (the implementor)
|
private int |
bufferSize
Number of bytes to be filled before process() invocation(s).
|
private int |
chunkSize
Number of bytes processed per process() invocation.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractStreamingHasher(int chunkSize)
Constructor for use by subclasses.
|
protected |
AbstractStreamingHasher(int chunkSize,
int bufferSize)
Constructor for use by subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
HashCode |
hash()
Computes a hash code based on the data that have been provided to this hasher.
|
protected abstract HashCode |
makeHash()
Computes a hash code based on the data that have been provided to this hasher.
|
private void |
munch() |
private void |
munchIfFull() |
protected abstract void |
process(java.nio.ByteBuffer bb)
Processes the available bytes of the buffer (at most
chunk bytes). |
protected void |
processRemaining(java.nio.ByteBuffer bb)
This is invoked for the last bytes of the input, which are not enough to fill a whole chunk.
|
Hasher |
putByte(byte b)
Puts a byte into this sink.
|
Hasher |
putBytes(byte[] bytes,
int off,
int len)
Puts a chunk of an array of bytes into this sink.
|
Hasher |
putBytes(java.nio.ByteBuffer readBuffer)
Puts the remaining bytes of a byte buffer into this sink.
|
private Hasher |
putBytesInternal(java.nio.ByteBuffer readBuffer) |
Hasher |
putChar(char c)
Puts a character into this sink.
|
Hasher |
putInt(int i)
Puts an int into this sink.
|
Hasher |
putLong(long l)
Puts a long into this sink.
|
Hasher |
putShort(short s)
Puts a short into this sink.
|
putBoolean, putBytes, putDouble, putFloat, putObject, putString, putUnencodedCharsprivate final java.nio.ByteBuffer buffer
private final int bufferSize
private final int chunkSize
protected AbstractStreamingHasher(int chunkSize)
chunkSize - the number of bytes available per process(ByteBuffer) invocation;
must be at least 4protected AbstractStreamingHasher(int chunkSize,
int bufferSize)
bufferSize size, which must be a multiple of chunkSize.chunkSize - the number of bytes available per process(ByteBuffer) invocation;
must be at least 4bufferSize - the size of the internal buffer. Must be a multiple of chunkSizeprotected abstract void process(java.nio.ByteBuffer bb)
chunk bytes).protected void processRemaining(java.nio.ByteBuffer bb)
ByteBuffer is guaranteed to be non-empty.
This implementation simply pads with zeros and delegates to process(ByteBuffer).
public final Hasher putBytes(byte[] bytes, int off, int len)
PrimitiveSinkbytes[off] is the first byte written,
bytes[off + len - 1] is the last.putBytes in interface HasherputBytes in interface PrimitiveSinkputBytes in class AbstractHasherbytes - a byte arrayoff - the start offset in the arraylen - the number of bytes to writepublic final Hasher putBytes(java.nio.ByteBuffer readBuffer)
PrimitiveSinkbytes.position() is the first
byte written, bytes.limit() - 1 is the last. The position of the buffer will be equal
to the limit when this method returns.putBytes in interface HasherputBytes in interface PrimitiveSinkputBytes in class AbstractHasherreadBuffer - a byte bufferprivate Hasher putBytesInternal(java.nio.ByteBuffer readBuffer)
public final Hasher putByte(byte b)
PrimitiveSinkb - a bytepublic final Hasher putShort(short s)
PrimitiveSinkputShort in interface HasherputShort in interface PrimitiveSinkputShort in class AbstractHasherpublic final Hasher putChar(char c)
PrimitiveSinkputChar in interface HasherputChar in interface PrimitiveSinkputChar in class AbstractHasherpublic final Hasher putInt(int i)
PrimitiveSinkputInt in interface HasherputInt in interface PrimitiveSinkputInt in class AbstractHasherpublic final Hasher putLong(long l)
PrimitiveSinkputLong in interface HasherputLong in interface PrimitiveSinkputLong in class AbstractHasherpublic final HashCode hash()
Hasherprotected abstract HashCode makeHash()
process(java.nio.ByteBuffer) and any leftover bytes that did not make a
complete chunk are handled with processRemaining(java.nio.ByteBuffer).private void munchIfFull()
private void munch()