Class HashingInputStream

  • All Implemented Interfaces:
    ,

    @Beta
    public final class HashingInputStream
    extends 
    An that maintains a hash of the data read from it.
    Since:
    16.0
    Author:
    Qian Huang
    • Field Summary

      • Fields inherited from class java.io.

    • Constructor Summary

      Constructors 
      Constructor Description
      HashingInputStream​(HashFunction hashFunction,  in)
      Creates an input stream that hashes using the given HashFunction and delegates all data read from it to the underlying .
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HashCode hash()
      Returns the HashCode based on the data read from this stream.
      void mark​(int readlimit)
      mark() is not supported for HashingInputStream
      boolean markSupported()
      mark() is not supported for HashingInputStream
      int read()
      Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.
      int read​(byte[] bytes, int off, int len)
      Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.
      void reset()
      reset() is not supported for HashingInputStream.
      • Methods inherited from class java.io.

        , , ,
      • Methods inherited from class java.io.

        , , , ,
      • Methods inherited from class java.lang.

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

      • HashingInputStream

        public HashingInputStream​(HashFunction hashFunction,
                                   in)
        Creates an input stream that hashes using the given HashFunction and delegates all data read from it to the underlying .

        The should not be read from before or after the hand-off.

    • Method Detail

      • read

        public int read()
                 throws 
        Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.
        Overrides:
         in class 
        Returns:
        the next byte of data, or -1 if the end of the stream is reached.
        Throws:
        - if an I/O error occurs.
        See Also:
      • read

        public int read​(byte[] bytes,
                        int off,
                        int len)
                 throws 
        Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.
        Overrides:
         in class 
        Parameters:
        bytes - the buffer into which the data is read.
        off - the start offset in the destination array b
        len - the maximum number of bytes read.
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        - if an I/O error occurs.
        See Also:
      • markSupported

        public boolean markSupported()
        mark() is not supported for HashingInputStream
        Overrides:
         in class 
        Returns:
        false always
        See Also:
        , ,
      • mark

        public void mark​(int readlimit)
        mark() is not supported for HashingInputStream
        Overrides:
         in class 
        Parameters:
        readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
        See Also:
        ,
      • reset

        public void reset()
                   throws 
        reset() is not supported for HashingInputStream.
        Overrides:
         in class 
        Throws:
        - this operation is not supported
        See Also:
        ,
      • hash

        public HashCode hash()
        Returns the HashCode based on the data read from this stream. The result is unspecified if this method is called more than once on the same instance.