Class AbstractStreamingHashFunction
- java.lang.Object
-
- com.google.common.hash.AbstractStreamingHashFunction
-
- All Implemented Interfaces:
HashFunction
- Direct Known Subclasses:
AbstractCompositeHashFunction
,ChecksumHashFunction
,Crc32cHashFunction
,MacHashFunction
,MessageDigestHashFunction
,Murmur3_128HashFunction
,Murmur3_32HashFunction
,SipHashFunction
abstract class AbstractStreamingHashFunction extends java.lang.Object implements HashFunction
Skeleton implementation ofHashFunction
. Provides default implementations which invokes the appropriate method onHashFunction.newHasher()
, then return the result ofHasher.hash()
.Invocations of
newHasher(int)
also delegate to HashFunction.newHasher(), ignoring the expected input size parameter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractStreamingHashFunction.AbstractStreamingHasher
A convenience base class for implementors ofHasher
; handles accumulating data until an entire "chunk" (of implementation-dependent length) is ready to be hashed.
-
Constructor Summary
Constructors Constructor Description AbstractStreamingHashFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HashCode
hashBytes(byte[] input)
Shortcut fornewHasher().putBytes(input).hash()
.HashCode
hashBytes(byte[] input, int off, int len)
Shortcut fornewHasher().putBytes(input, off, len).hash()
.HashCode
hashInt(int input)
Shortcut fornewHasher().putInt(input).hash()
; returns the hash code for the givenint
value, interpreted in little-endian byte order.HashCode
hashLong(long input)
Shortcut fornewHasher().putLong(input).hash()
; returns the hash code for the givenlong
value, interpreted in little-endian byte order.<T> HashCode
hashObject(T instance, Funnel<? super T> funnel)
Shortcut fornewHasher().putObject(instance, funnel).hash()
.HashCode
hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
Shortcut fornewHasher().putString(input, charset).hash()
.HashCode
hashUnencodedChars(java.lang.CharSequence input)
Shortcut fornewHasher().putUnencodedChars(input).hash()
.Hasher
newHasher(int expectedInputSize)
Begins a new hash code computation asHashFunction.newHasher()
, but provides a hint of the expected size of the input (in bytes).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.common.hash.HashFunction
bits, newHasher
-
-
-
-
Method Detail
-
hashObject
public <T> HashCode hashObject(T instance, Funnel<? super T> funnel)
Description copied from interface:HashFunction
Shortcut fornewHasher().putObject(instance, funnel).hash()
. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashObject
in interfaceHashFunction
-
hashUnencodedChars
public HashCode hashUnencodedChars(java.lang.CharSequence input)
Description copied from interface:HashFunction
Shortcut fornewHasher().putUnencodedChars(input).hash()
. The implementation might perform better than its longhand equivalent, but should not perform worse. Note that no character encoding is performed; the low byte and high byte of eachchar
are hashed directly (in that order).Warning: This method will produce different output than most other languages do when running the same hash function on the equivalent input. For cross-language compatibility, use
HashFunction.hashString(java.lang.CharSequence, java.nio.charset.Charset)
, usually with a charset of UTF-8. For other use cases, usehashUnencodedChars
.- Specified by:
hashUnencodedChars
in interfaceHashFunction
-
hashString
public HashCode hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
Description copied from interface:HashFunction
Shortcut fornewHasher().putString(input, charset).hash()
. Characters are encoded using the givenCharset
. The implementation might perform better than its longhand equivalent, but should not perform worse.Warning: This method, which reencodes the input before hashing it, is useful only for cross-language compatibility. For other use cases, prefer
HashFunction.hashUnencodedChars(java.lang.CharSequence)
, which is faster, produces the same output across Java releases, and hashes everychar
in the input, even if some are invalid.- Specified by:
hashString
in interfaceHashFunction
-
hashInt
public HashCode hashInt(int input)
Description copied from interface:HashFunction
Shortcut fornewHasher().putInt(input).hash()
; returns the hash code for the givenint
value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashInt
in interfaceHashFunction
-
hashLong
public HashCode hashLong(long input)
Description copied from interface:HashFunction
Shortcut fornewHasher().putLong(input).hash()
; returns the hash code for the givenlong
value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashLong
in interfaceHashFunction
-
hashBytes
public HashCode hashBytes(byte[] input)
Description copied from interface:HashFunction
Shortcut fornewHasher().putBytes(input).hash()
. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashBytes
in interfaceHashFunction
-
hashBytes
public HashCode hashBytes(byte[] input, int off, int len)
Description copied from interface:HashFunction
Shortcut fornewHasher().putBytes(input, off, len).hash()
. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashBytes
in interfaceHashFunction
-
newHasher
public Hasher newHasher(int expectedInputSize)
Description copied from interface:HashFunction
Begins a new hash code computation asHashFunction.newHasher()
, but provides a hint of the expected size of the input (in bytes). This is only important for non-streaming hash functions (hash functions that need to buffer their whole input before processing any of it).- Specified by:
newHasher
in interfaceHashFunction
-
-