Class Sha256InputStreamDecorator

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Sha256InputStreamDecorator
    extends java.io.InputStream
    Decorates an InputStream with the ability to compute a SHA-256 hash of the bytes read from the stream. Assumes that the entire stream is read. If buffering is done further up-stream, then obviously the digest may not represent what was actually read by the consumer, because the buffer may read bytes from this stream than were actually consumed. Caveat emptor.
    • Constructor Summary

      Constructors 
      Constructor Description
      Sha256InputStreamDecorator​(java.io.InputStream delegate)
      Public Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.lang.String getBase64Hash()
      Compute the digest.
      int read()  
      int read​(byte[] b, int off, int len)  
      • Methods inherited from class java.io.InputStream

        available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Sha256InputStreamDecorator

        public Sha256InputStreamDecorator​(java.io.InputStream delegate)
        Public Constructor
        Parameters:
        delegate - the delegate stream we are decorating
    • Method Detail

      • getBase64Hash

        public java.lang.String getBase64Hash()
        Compute the digest. Resets the state
        Returns:
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException