protected abstract static class AbstractStreamingHashFunction.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.
|
(package private) abstract HashCode |
makeHash() |
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)
Puts an array of bytes into this sink.
|
Hasher |
putBytes(byte[] bytes,
int off,
int len)
Puts a chunk of an array of bytes into this sink.
|
private Hasher |
putBytes(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.
|
<T> Hasher |
putObject(T instance,
Funnel<? super T> funnel)
A simple convenience for
funnel.funnel(object, this). |
Hasher |
putShort(short s)
Puts a short into this sink.
|
Hasher |
putUnencodedChars(java.lang.CharSequence charSequence)
Equivalent to processing each
char value in the CharSequence, in order. |
putBoolean, putDouble, putFloat, putStringprivate 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)
PrimitiveSinkbytes - a byte arraypublic final Hasher putBytes(byte[] bytes, int off, int len)
PrimitiveSinkbytes[off] is the first byte written,
bytes[off + len - 1] is the last.bytes - a byte arrayoff - the start offset in the arraylen - the number of bytes to writeprivate Hasher putBytes(java.nio.ByteBuffer readBuffer)
public final Hasher putUnencodedChars(java.lang.CharSequence charSequence)
Hasherchar value in the CharSequence, in order.
The input must not be updated while this method is in progress.putUnencodedChars in interface HasherputUnencodedChars in interface PrimitiveSinkputUnencodedChars in class AbstractHasherpublic final Hasher putByte(byte b)
PrimitiveSinkb - a bytepublic final Hasher putShort(short s)
PrimitiveSinkpublic final Hasher putChar(char c)
PrimitiveSinkpublic final Hasher putInt(int i)
PrimitiveSinkpublic final Hasher putLong(long l)
PrimitiveSinkpublic final <T> Hasher putObject(T instance, Funnel<? super T> funnel)
Hasherfunnel.funnel(object, this).public final HashCode hash()
Hasherabstract HashCode makeHash()
private void munchIfFull()
private void munch()