com.google.common.hash

## Class HashingOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - com.google.common.hash.HashingOutputStream

- All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

      @Beta
      public final class HashingOutputStream
      extends java.io.FilterOutputStream

  An `OutputStream` that maintains a hash of the data written to it.
  Since:
    16.0

- - ### Field Summary

    - ### Fields inherited from class java.io.FilterOutputStream

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HashingOutputStream(HashFunction hashFunction, java.io.OutputStream out)` Creates an output stream that hashes using the given `HashFunction`, and forwards all data written to it to the underlying `OutputStream`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `HashCode` | `hash()` Returns the `HashCode` based on the data written to this stream.
    `void` | `write(byte[] bytes, int off, int len)`
    `void` | `write(int b)`

    - ### Methods inherited from class java.io.FilterOutputStream

      `flush, write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### HashingOutputStream

          public HashingOutputStream(HashFunction hashFunction,
                             java.io.OutputStream out)

      Creates an output stream that hashes using the given `HashFunction`, and forwards all data written to it to the underlying `OutputStream`.

      The `OutputStream` should not be written to before or after the hand-off.

  - ### Method Detail

    - #### write

          public void write(int b)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`

    - #### write

          public void write(byte[] bytes,
                   int off,
                   int len)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`

    - #### hash

          @CheckReturnValue
          public HashCode hash()

      Returns the `HashCode` based on the data written to this stream. The result is unspecified if this method is called more than once on the same instance.

    - #### close

          public void close()
                     throws java.io.IOException

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`