Class DigesterOutputStream

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

    public class DigesterOutputStream
    extends java.io.OutputStream
    This class has been modified slightly to use java.security.MessageDigest objects as input, rather than org.apache.xml.security.algorithms.MessageDigestAlgorithm objects. It also optionally caches the input bytes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private UnsyncByteArrayOutputStream bos  
      private boolean buffer  
      private static org.slf4j.Logger LOG  
      private java.security.MessageDigest md  
    • Constructor Summary

      Constructors 
      Constructor Description
      DigesterOutputStream​(java.security.MessageDigest md)
      Creates a DigesterOutputStream.
      DigesterOutputStream​(java.security.MessageDigest md, boolean buffer)
      Creates a DigesterOutputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      byte[] getDigestValue()  
      java.io.InputStream getInputStream()  
      void write​(byte[] input, int offset, int len)  
      void write​(int input)  
      • Methods inherited from class java.io.OutputStream

        flush, nullOutputStream, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • buffer

        private final boolean buffer
      • md

        private final java.security.MessageDigest md
    • Constructor Detail

      • DigesterOutputStream

        public DigesterOutputStream​(java.security.MessageDigest md)
        Creates a DigesterOutputStream.
        Parameters:
        md - the MessageDigest
      • DigesterOutputStream

        public DigesterOutputStream​(java.security.MessageDigest md,
                                    boolean buffer)
        Creates a DigesterOutputStream.
        Parameters:
        md - the MessageDigest
        buffer - if true, caches the input bytes
    • Method Detail

      • write

        public void write​(int input)
        Specified by:
        write in class java.io.OutputStream
      • write

        public void write​(byte[] input,
                          int offset,
                          int len)
        Overrides:
        write in class java.io.OutputStream
      • getDigestValue

        public byte[] getDigestValue()
        Returns:
        the digest value
      • getInputStream

        public java.io.InputStream getInputStream()
        Returns:
        an input stream containing the cached bytes, or null if not cached
      • 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.OutputStream
        Throws:
        java.io.IOException