Package com.google.common.hash
Class AbstractByteHasher
java.lang.Object
com.google.common.hash.AbstractHasher
com.google.common.hash.AbstractByteHasher
- All Implemented Interfaces:
Hasher,PrimitiveSink
- Direct Known Subclasses:
ChecksumHashFunction.ChecksumHasher,MacHashFunction.MacHasher,MessageDigestHashFunction.MessageDigestHasher
Abstract
Hasher that handles converting primitives to bytes using a scratch
ByteBuffer and streams all bytes to a sink to compute the hash.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionputByte(byte b) Puts a byte into this sink.putBytes(byte[] bytes) Puts an array of bytes into this sink.putBytes(byte[] bytes, int off, int len) Puts a chunk of an array of bytes into this sink.putBytes(ByteBuffer bytes) Puts the remaining bytes of a byte buffer into this sink.putChar(char c) Puts a character into this sink.putInt(int i) Puts an int into this sink.putLong(long l) Puts a long into this sink.putShort(short s) Puts a short into this sink.protected abstract voidupdate(byte b) Updates this hasher with the given byte.protected voidupdate(byte[] b) Updates this hasher with the given bytes.protected voidupdate(byte[] b, int off, int len) Updates this hasher withlenbytes starting atoffin the given buffer.private Hasherupdate(int bytes) Updates the sink with the given number of bytes from the buffer.protected voidupdate(ByteBuffer b) Updates this hasher with bytes from the given buffer.Methods inherited from class com.google.common.hash.AbstractHasher
putBoolean, putDouble, putFloat, putObject, putString, putUnencodedChars
-
Field Details
-
scratch
-
-
Constructor Details
-
AbstractByteHasher
AbstractByteHasher()
-
-
Method Details
-
update
protected abstract void update(byte b) Updates this hasher with the given byte. -
update
protected void update(byte[] b) Updates this hasher with the given bytes. -
update
protected void update(byte[] b, int off, int len) Updates this hasher withlenbytes starting atoffin the given buffer. -
update
Updates this hasher with bytes from the given buffer. -
update
Updates the sink with the given number of bytes from the buffer. -
putByte
Description copied from interface:PrimitiveSinkPuts a byte into this sink.- Parameters:
b- a byte- Returns:
- this instance
-
putBytes
Description copied from interface:PrimitiveSinkPuts an array of bytes into this sink.- Specified by:
putBytesin interfaceHasher- Specified by:
putBytesin interfacePrimitiveSink- Overrides:
putBytesin classAbstractHasher- Parameters:
bytes- a byte array- Returns:
- this instance
-
putBytes
Description copied from interface:PrimitiveSinkPuts a chunk of an array of bytes into this sink.bytes[off]is the first byte written,bytes[off + len - 1]is the last.- Specified by:
putBytesin interfaceHasher- Specified by:
putBytesin interfacePrimitiveSink- Overrides:
putBytesin classAbstractHasher- Parameters:
bytes- a byte arrayoff- the start offset in the arraylen- the number of bytes to write- Returns:
- this instance
-
putBytes
Description copied from interface:PrimitiveSinkPuts the remaining bytes of a byte buffer into this sink.bytes.position()is the first byte written,bytes.limit() - 1is the last. The position of the buffer will be equal to the limit when this method returns.- Specified by:
putBytesin interfaceHasher- Specified by:
putBytesin interfacePrimitiveSink- Overrides:
putBytesin classAbstractHasher- Parameters:
bytes- a byte buffer- Returns:
- this instance
-
putShort
Description copied from interface:PrimitiveSinkPuts a short into this sink.- Specified by:
putShortin interfaceHasher- Specified by:
putShortin interfacePrimitiveSink- Overrides:
putShortin classAbstractHasher
-
putInt
Description copied from interface:PrimitiveSinkPuts an int into this sink.- Specified by:
putIntin interfaceHasher- Specified by:
putIntin interfacePrimitiveSink- Overrides:
putIntin classAbstractHasher
-
putLong
Description copied from interface:PrimitiveSinkPuts a long into this sink.- Specified by:
putLongin interfaceHasher- Specified by:
putLongin interfacePrimitiveSink- Overrides:
putLongin classAbstractHasher
-
putChar
Description copied from interface:PrimitiveSinkPuts a character into this sink.- Specified by:
putCharin interfaceHasher- Specified by:
putCharin interfacePrimitiveSink- Overrides:
putCharin classAbstractHasher
-