abstract class AbstractNonStreamingHashFunction extends AbstractHashFunction
HashFunction
, appropriate for non-streaming algorithms. All
the hash computation done using newHasher() are delegated to the hashBytes(byte[], int, int) method.Modifier and Type | Class and Description |
---|---|
private class |
AbstractNonStreamingHashFunction.BufferingHasher
In-memory stream-based implementation of Hasher.
|
private static class |
AbstractNonStreamingHashFunction.ExposedByteArrayOutputStream |
Constructor and Description |
---|
AbstractNonStreamingHashFunction() |
Modifier and Type | Method and Description |
---|---|
abstract HashCode |
hashBytes(byte[] input,
int off,
int len)
Shortcut for
newHasher().putBytes(input, off, len).hash() . |
HashCode |
hashBytes(java.nio.ByteBuffer input)
Shortcut for
newHasher().putBytes(input).hash() . |
HashCode |
hashInt(int input)
Shortcut for
newHasher().putInt(input).hash() ; returns the hash code for the given
int value, interpreted in little-endian byte order. |
HashCode |
hashLong(long input)
Shortcut for
newHasher().putLong(input).hash() ; returns the hash code for the given
long value, interpreted in little-endian byte order. |
HashCode |
hashString(java.lang.CharSequence input,
java.nio.charset.Charset charset)
Shortcut for
newHasher().putString(input, charset).hash() . |
HashCode |
hashUnencodedChars(java.lang.CharSequence input)
Shortcut for
newHasher().putUnencodedChars(input).hash() . |
Hasher |
newHasher()
Begins a new hash code computation by returning an initialized, stateful
Hasher
instance that is ready to receive data. |
Hasher |
newHasher(int expectedInputSize)
Begins a new hash code computation as
HashFunction.newHasher() , but provides a hint of the expected
size of the input (in bytes). |
hashBytes, hashObject
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
bits
public Hasher newHasher()
HashFunction
Hasher
instance that is ready to receive data. Example:
HashFunction hf = Hashing.md5();
HashCode hc = hf.newHasher()
.putLong(id)
.putBoolean(isActive)
.hash();
public Hasher newHasher(int expectedInputSize)
HashFunction
HashFunction.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).newHasher
in interface HashFunction
newHasher
in class AbstractHashFunction
public HashCode hashInt(int input)
HashFunction
newHasher().putInt(input).hash()
; returns the hash code for the given
int
value, interpreted in little-endian byte order. The implementation might
perform better than its longhand equivalent, but should not perform worse.hashInt
in interface HashFunction
hashInt
in class AbstractHashFunction
public HashCode hashLong(long input)
HashFunction
newHasher().putLong(input).hash()
; returns the hash code for the given
long
value, interpreted in little-endian byte order. The implementation might
perform better than its longhand equivalent, but should not perform worse.hashLong
in interface HashFunction
hashLong
in class AbstractHashFunction
public HashCode hashUnencodedChars(java.lang.CharSequence input)
HashFunction
newHasher().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 each char
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, use hashUnencodedChars
.
hashUnencodedChars
in interface HashFunction
hashUnencodedChars
in class AbstractHashFunction
public HashCode hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
HashFunction
newHasher().putString(input, charset).hash()
. Characters are encoded using
the given Charset
. 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 every char
in the
input, even if some are invalid.
hashString
in interface HashFunction
hashString
in class AbstractHashFunction
public abstract HashCode hashBytes(byte[] input, int off, int len)
HashFunction
newHasher().putBytes(input, off, len).hash()
. The implementation
might perform better than its longhand equivalent, but should not perform worse.hashBytes
in interface HashFunction
hashBytes
in class AbstractHashFunction
public HashCode hashBytes(java.nio.ByteBuffer input)
HashFunction
newHasher().putBytes(input).hash()
. The implementation might
perform better than its longhand equivalent, but should not perform worse.hashBytes
in interface HashFunction
hashBytes
in class AbstractHashFunction