Top Description Inners Constructors Methods
com.google.common.hash

pack-priv abstract Class AbstractNonStreamingHashFunction

extends AbstractHashFunction
Class Inheritance
Known Direct Subclasses
com.google.common.hash.FarmHashFingerprint64, com.google.common.hash.Fingerprint2011
Annotations
@Immutable
@ElementTypesAreNonnullByDefault
Imports
com.google.common.base.Preconditions, com.google.errorprone.annotations.Immutable, java.io.ByteArrayOutputStream, java.nio.ByteBuffer, .ByteOrder, java.nio.charset.Charset, java.util.Arrays

Skeleton implementation of HashFunction, appropriate for non-streaming algorithms. All the hash computation done using newHasher() are delegated to the hashBytes(byte[], int, int) method.
Author
Dimitris Andreou

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
AbstractNonStreamingHashFunction.BufferingHasher

In-memory stream-based implementation of Hasher.

private static class

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public abstract HashCode
hashBytes(byte[] input, int off, int len)

Redeclares com.google.common.hash.HashFunction.hashBytes.

Overrides com.google.common.hash.AbstractHashFunction.hashBytes.

Shortcut for newHasher().putBytes(input, off, len).hash().
public HashCode
hashBytes(ByteBuffer input)

Overrides com.google.common.hash.AbstractHashFunction.hashBytes.

Implements com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input).hash().
public HashCode
hashInt(int input)

Overrides com.google.common.hash.AbstractHashFunction.hashInt.

Implements com.google.common.hash.HashFunction.hashInt.

Shortcut for newHasher().putInt(input).hash(); returns the hash code for the given int value, interpreted in little-endian byte order.
public HashCode
hashLong(long input)

Overrides com.google.common.hash.AbstractHashFunction.hashLong.

Implements com.google.common.hash.HashFunction.hashLong.

Shortcut for newHasher().putLong(input).hash(); returns the hash code for the given long value, interpreted in little-endian byte order.
public HashCode
hashString(CharSequence input, Charset charset)

Overrides com.google.common.hash.AbstractHashFunction.hashString.

Implements com.google.common.hash.HashFunction.hashString.

Shortcut for newHasher().putString(input, charset).hash().
public HashCode
public Hasher
newHasher()

Implements com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation by returning an initialized, stateful Hasher instance that is ready to receive data.
public Hasher
newHasher(int expectedInputSize)

Overrides com.google.common.hash.AbstractHashFunction.newHasher.

Implements com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation as newHasher(), but provides a hint of the expected size of the input (in bytes).
Inherited from com.google.common.hash.AbstractHashFunction:
hashByteshashObject

Constructor Detail

AbstractNonStreamingHashFunctionback to summary
pack-priv AbstractNonStreamingHashFunction()

Method Detail

hashBytesback to summary
public abstract HashCode hashBytes(byte[] input, int off, int len)

Redeclares com.google.common.hash.HashFunction.hashBytes.

Overrides com.google.common.hash.AbstractHashFunction.hashBytes.

Doc from com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input, off, len).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashBytesback to summary
public HashCode hashBytes(ByteBuffer input)

Overrides com.google.common.hash.AbstractHashFunction.hashBytes.

Implements com.google.common.hash.HashFunction.hashBytes.

Doc from com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashIntback to summary
public HashCode hashInt(int input)

Overrides com.google.common.hash.AbstractHashFunction.hashInt.

Implements com.google.common.hash.HashFunction.hashInt.

Doc from com.google.common.hash.HashFunction.hashInt.

Shortcut for 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.

Annotations
@Override
hashLongback to summary
public HashCode hashLong(long input)

Overrides com.google.common.hash.AbstractHashFunction.hashLong.

Implements com.google.common.hash.HashFunction.hashLong.

Doc from com.google.common.hash.HashFunction.hashLong.

Shortcut for 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.

Annotations
@Override
hashStringback to summary
public HashCode hashString(CharSequence input, Charset charset)

Overrides com.google.common.hash.AbstractHashFunction.hashString.

Implements com.google.common.hash.HashFunction.hashString.

Doc from com.google.common.hash.HashFunction.hashString.

Shortcut for 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 hashUnencodedChars, which is faster, produces the same output across Java releases, and hashes every char in the input, even if some are invalid.

Annotations
@Override
hashUnencodedCharsback to summary
public HashCode hashUnencodedChars(CharSequence input)

Overrides com.google.common.hash.AbstractHashFunction.hashUnencodedChars.

Implements com.google.common.hash.HashFunction.hashUnencodedChars.

Doc from com.google.common.hash.HashFunction.hashUnencodedChars.

Shortcut for 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 hashString, usually with a charset of UTF-8. For other use cases, use hashUnencodedChars.

Annotations
@Override
newHasherback to summary
public Hasher newHasher()

Implements com.google.common.hash.HashFunction.newHasher.

Doc from com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation by returning an initialized, stateful Hasher instance that is ready to receive data. Example:

HashFunction hf = Hashing.md5();
HashCode hc = hf.newHasher()
    .putLong(id)
    .putBoolean(isActive)
    .hash();
Annotations
@Override
newHasherback to summary
public Hasher newHasher(int expectedInputSize)

Overrides com.google.common.hash.AbstractHashFunction.newHasher.

Implements com.google.common.hash.HashFunction.newHasher.

Doc from com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation as 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).

Annotations
@Override
com.google.common.hash back to summary

private final Class AbstractNonStreamingHashFunction.BufferingHasher

extends AbstractHasher
Class Inheritance

In-memory stream-based implementation of Hasher.

Field Summary

Modifier and TypeField and Description
pack-priv final AbstractNonStreamingHashFunction.ExposedByteArrayOutputStream

Constructor Summary

AccessConstructor and Description
pack-priv
BufferingHasher(int expectedInputSize)

Method Summary

Modifier and TypeMethod and Description
public HashCode
hash()

Implements com.google.common.hash.Hasher.hash.

Computes a hash code based on the data that have been provided to this hasher.
public Hasher
putByte(byte
a byte
b
)

Implements com.google.common.hash.Hasher.putByte.

Puts a byte into this sink.
public Hasher
putBytes(byte[]
a byte array
bytes
,
int
the start offset in the array
off
,
int
the number of bytes to write
len
)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Puts a chunk of an array of bytes into this sink.
public Hasher
putBytes(ByteBuffer
a byte buffer
bytes
)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Puts the remaining bytes of a byte buffer into this sink.
Inherited from com.google.common.hash.AbstractHasher:
putBooleanputBytesputCharputDoubleputFloatputIntputLongputObjectputShortputStringputUnencodedChars

Field Detail

streamback to summary
pack-priv final AbstractNonStreamingHashFunction.ExposedByteArrayOutputStream stream

Constructor Detail

BufferingHasherback to summary
pack-priv BufferingHasher(int expectedInputSize)

Method Detail

hashback to summary
public HashCode hash()

Implements com.google.common.hash.Hasher.hash.

Doc from com.google.common.hash.Hasher.hash.

Computes a hash code based on the data that have been provided to this hasher. The result is unspecified if this method is called more than once on the same instance.

Annotations
@Override
putByteback to summary
public Hasher putByte(byte b)

Implements com.google.common.hash.Hasher.putByte.

Doc from com.google.common.hash.PrimitiveSink.putByte.

Puts a byte into this sink.

Parameters
b:byte

a byte

Returns:Hasher

this instance

Annotations
@Override
putBytesback to summary
public Hasher putBytes(byte[] bytes, int off, int len)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

Puts a chunk of an array of bytes into this sink. bytes[off] is the first byte written, bytes[off + len - 1] is the last.

Parameters
bytes:byte[]

a byte array

off:int

the start offset in the array

len:int

the number of bytes to write

Returns:Hasher

this instance

Annotations
@Override
putBytesback to summary
public Hasher putBytes(ByteBuffer bytes)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

Puts the remaining bytes of a byte buffer into this sink. 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.

Parameters
bytes:ByteBuffer

a byte buffer

Returns:Hasher

this instance

Annotations
@Override
com.google.common.hash back to summary

private final Class AbstractNonStreamingHashFunction.ExposedByteArrayOutputStream

extends ByteArrayOutputStream
Class Inheritance

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
pack-priv
ExposedByteArrayOutputStream(int expectedInputSize)

Method Summary

Modifier and TypeMethod and Description
pack-priv byte[]
pack-priv int
pack-priv void
Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

ExposedByteArrayOutputStreamback to summary
pack-priv ExposedByteArrayOutputStream(int expectedInputSize)

Method Detail

byteArrayback to summary
pack-priv byte[] byteArray()
lengthback to summary
pack-priv int length()
writeback to summary
pack-priv void write(ByteBuffer input)