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 class AbstractByteHasher extends AbstractHasher
Abstract Hasher that handles converting primitives to bytes using a scratch ByteBuffer and streams all bytes to a sink to compute the hash.
  • Field Details

  • 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 with len bytes starting at off in the given buffer.
    • update

      protected void update(ByteBuffer b)
      Updates this hasher with bytes from the given buffer.
    • update

      private Hasher update(int bytes)
      Updates the sink with the given number of bytes from the buffer.
    • putByte

      public Hasher putByte(byte b)
      Description copied from interface: PrimitiveSink
      Puts a byte into this sink.
      Parameters:
      b - a byte
      Returns:
      this instance
    • putBytes

      public Hasher putBytes(byte[] bytes)
      Description copied from interface: PrimitiveSink
      Puts an array of bytes into this sink.
      Specified by:
      putBytes in interface Hasher
      Specified by:
      putBytes in interface PrimitiveSink
      Overrides:
      putBytes in class AbstractHasher
      Parameters:
      bytes - a byte array
      Returns:
      this instance
    • putBytes

      public Hasher putBytes(byte[] bytes, int off, int len)
      Description copied from interface: PrimitiveSink
      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.
      Specified by:
      putBytes in interface Hasher
      Specified by:
      putBytes in interface PrimitiveSink
      Overrides:
      putBytes in class AbstractHasher
      Parameters:
      bytes - a byte array
      off - the start offset in the array
      len - the number of bytes to write
      Returns:
      this instance
    • putBytes

      public Hasher putBytes(ByteBuffer bytes)
      Description copied from interface: PrimitiveSink
      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.
      Specified by:
      putBytes in interface Hasher
      Specified by:
      putBytes in interface PrimitiveSink
      Overrides:
      putBytes in class AbstractHasher
      Parameters:
      bytes - a byte buffer
      Returns:
      this instance
    • putShort

      public Hasher putShort(short s)
      Description copied from interface: PrimitiveSink
      Puts a short into this sink.
      Specified by:
      putShort in interface Hasher
      Specified by:
      putShort in interface PrimitiveSink
      Overrides:
      putShort in class AbstractHasher
    • putInt

      public Hasher putInt(int i)
      Description copied from interface: PrimitiveSink
      Puts an int into this sink.
      Specified by:
      putInt in interface Hasher
      Specified by:
      putInt in interface PrimitiveSink
      Overrides:
      putInt in class AbstractHasher
    • putLong

      public Hasher putLong(long l)
      Description copied from interface: PrimitiveSink
      Puts a long into this sink.
      Specified by:
      putLong in interface Hasher
      Specified by:
      putLong in interface PrimitiveSink
      Overrides:
      putLong in class AbstractHasher
    • putChar

      public Hasher putChar(char c)
      Description copied from interface: PrimitiveSink
      Puts a character into this sink.
      Specified by:
      putChar in interface Hasher
      Specified by:
      putChar in interface PrimitiveSink
      Overrides:
      putChar in class AbstractHasher