abstract class AbstractByteHasher extends AbstractHasher
Hasher
that handles converting primitives to bytes using a scratch ByteBuffer
and streams all bytes to a sink to compute the hash.Modifier and Type | Field and Description |
---|---|
private java.nio.ByteBuffer |
scratch |
Constructor and Description |
---|
AbstractByteHasher() |
Modifier and Type | Method and Description |
---|---|
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.
|
Hasher |
putBytes(java.nio.ByteBuffer bytes)
Puts the remaining bytes of a byte buffer into this sink.
|
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.
|
protected abstract void |
update(byte b)
Updates this hasher with the given byte.
|
protected void |
update(byte[] b)
Updates this hasher with the given bytes.
|
protected void |
update(byte[] b,
int off,
int len)
Updates this hasher with
len bytes starting at off in the given buffer. |
protected void |
update(java.nio.ByteBuffer b)
Updates this hasher with bytes from the given buffer.
|
private Hasher |
update(int bytes)
Updates the sink with the given number of bytes from the buffer.
|
putBoolean, putDouble, putFloat, putObject, putString, putUnencodedChars
protected abstract void update(byte b)
protected void update(byte[] b)
protected void update(byte[] b, int off, int len)
len
bytes starting at off
in the given buffer.protected void update(java.nio.ByteBuffer b)
private Hasher update(int bytes)
public Hasher putByte(byte b)
PrimitiveSink
b
- a bytepublic Hasher putBytes(byte[] bytes)
PrimitiveSink
putBytes
in interface Hasher
putBytes
in interface PrimitiveSink
putBytes
in class AbstractHasher
bytes
- a byte arraypublic Hasher putBytes(byte[] bytes, int off, int len)
PrimitiveSink
bytes[off]
is the first byte written,
bytes[off + len - 1]
is the last.putBytes
in interface Hasher
putBytes
in interface PrimitiveSink
putBytes
in class AbstractHasher
bytes
- a byte arrayoff
- the start offset in the arraylen
- the number of bytes to writepublic Hasher putBytes(java.nio.ByteBuffer bytes)
PrimitiveSink
bytes.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 Hasher
putBytes
in interface PrimitiveSink
putBytes
in class AbstractHasher
bytes
- a byte bufferpublic Hasher putShort(short s)
PrimitiveSink
putShort
in interface Hasher
putShort
in interface PrimitiveSink
putShort
in class AbstractHasher
public Hasher putInt(int i)
PrimitiveSink
putInt
in interface Hasher
putInt
in interface PrimitiveSink
putInt
in class AbstractHasher
public Hasher putLong(long l)
PrimitiveSink
putLong
in interface Hasher
putLong
in interface PrimitiveSink
putLong
in class AbstractHasher
public Hasher putChar(char c)
PrimitiveSink
putChar
in interface Hasher
putChar
in interface PrimitiveSink
putChar
in class AbstractHasher