Package java.security

Class DigestOutputStream

    • Field Detail

      • digest

        protected MessageDigest digest
        The message digest for this stream.
    • Constructor Detail

      • DigestOutputStream

        public DigestOutputStream​(OutputStream stream,
                                  MessageDigest digest)
        Constructs a new instance of this DigestOutputStream, using the given stream and the digest.
        Parameters:
        stream - the output stream.
        digest - the message digest.
    • Method Detail

      • getMessageDigest

        public MessageDigest getMessageDigest()
        Returns the message digest for this stream.
        Returns:
        the message digest for this stream.
      • setMessageDigest

        public void setMessageDigest​(MessageDigest digest)
        Sets the message digest which this stream will use.
        Parameters:
        digest - the message digest which this stream will use.
      • write

        public void write​(int b)
                   throws IOException
        Writes the specified int to the stream. Updates the digest if this function is on(boolean).
        Overrides:
        write in class FilterOutputStream
        Parameters:
        b - the byte to be written.
        Throws:
        IOException - if writing to the stream causes a IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws IOException
        Writes len bytes into the stream, starting from the specified offset. Updates the digest if this function is on(boolean).
        Overrides:
        write in class FilterOutputStream
        Parameters:
        b - the buffer to write to.
        off - the index of the first byte in b to write.
        len - the number of bytes in b to write.
        Throws:
        IOException - if writing to the stream causes an IOException.
      • on

        public void on​(boolean on)
        Enables or disables the digest function (default is on).
        Parameters:
        on - true if the digest should be computed, false otherwise.
        See Also:
        MessageDigest
      • toString

        public String toString()
        Returns a string containing a concise, human-readable description of this DigestOutputStream including the digest.
        Overrides:
        toString in class Object
        Returns:
        a printable representation for this DigestOutputStream.