Class HashingOutputStream

  • All Implemented Interfaces:
    , ,

    @Beta
    public final class HashingOutputStream
    extends 
    An that maintains a hash of the data written to it.
    Since:
    16.0
    Author:
    Nick Piepmeier
    • Field Summary

      • Fields inherited from class java.io.

    • Constructor Summary

      Constructors 
      Constructor Description
      HashingOutputStream​(HashFunction hashFunction,  out)
      Creates an output stream that hashes using the given HashFunction, and forwards all data written to it to the underlying .
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this output stream and releases any system resources associated with the stream.
      HashCode hash()
      Returns the HashCode based on the data written to this stream.
      void write​(byte[] bytes, int off, int len)
      Writes len bytes from the specified byte array starting at offset off to this output stream.
      void write​(int b)
      Writes the specified byte to this output stream.
      • Methods inherited from class java.io.

        ,
      • Methods inherited from class java.io.

      • Methods inherited from class java.lang.

        , , , , , , , , , ,
    • Constructor Detail

      • HashingOutputStream

        public HashingOutputStream​(HashFunction hashFunction,
                                    out)
        Creates an output stream that hashes using the given HashFunction, and forwards all data written to it to the underlying .

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

    • Method Detail

      • write

        public void write​(int b)
                   throws 
        Description copied from class: 
        Writes the specified byte to this output stream.

        The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b).

        Implements the abstract write method of OutputStream.

        Overrides:
         in class 
        Parameters:
        b - the byte.
        Throws:
        - if an I/O error occurs.
      • write

        public void write​(byte[] bytes,
                          int off,
                          int len)
                   throws 
        Description copied from class: 
        Writes len bytes from the specified byte array starting at offset off to this output stream.

        The write method of FilterOutputStream calls the write method of one argument on each byte to output.

        Note that this method does not call the write method of its underlying output stream with the same arguments. Subclasses of FilterOutputStream should provide a more efficient implementation of this method.

        Overrides:
         in class 
        Parameters:
        bytes - the data.
        off - the start offset in the data.
        len - the number of bytes to write.
        Throws:
        - if an I/O error occurs.
        See Also:
      • hash

        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 
        Description copied from class: 
        Closes this output stream and releases any system resources associated with the stream.

        When not already closed, the close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream.

        Specified by:
         in interface 
        Specified by:
         in interface 
        Overrides:
         in class 
        Throws:
        - if an I/O error occurs.
        See Also:
        ,