Class ArmoredOutputStream

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

    public class ArmoredOutputStream
    extends java.io.OutputStream
    Output stream that writes data in ASCII Armored format.

    Note 1: close() needs to be called on an ArmoredOutputStream to write the final checksum. flush() will not do this as other classes assume it is always fine to call flush() - it is not though if the checksum gets output. Note 2: as multiple PGP blobs are often written to the same stream, close() does not close the underlying stream.

    • Constructor Detail

      • ArmoredOutputStream

        public ArmoredOutputStream​(java.io.OutputStream out)
        Constructs an armored output stream with default headers.
        Parameters:
        out - the OutputStream to wrap.
      • ArmoredOutputStream

        public ArmoredOutputStream​(java.io.OutputStream out,
                                   java.util.Hashtable<java.lang.String,​java.lang.String> headers)
        Constructs an armored output stream with default and custom headers.
        Parameters:
        out - the OutputStream to wrap.
        headers - additional headers that add to or override the default headers.
    • Method Detail

      • setHeader

        @Deprecated
        public void setHeader​(java.lang.String name,
                              java.lang.String value)
        Deprecated.
        use appropriate methods in ArmoredOutputStream.Builder instead.
        Set an additional header entry. Any current value(s) under the same name will be replaced by the new one. A null value will clear the entry for name.
        Parameters:
        name - the name of the header entry.
        value - the value of the header entry.
      • clearHeaders

        @Deprecated
        public void clearHeaders()
        Deprecated.
        use appropriate methods in ArmoredOutputStream.Builder instead.
        Remove all headers.
      • addHeader

        @Deprecated
        public void addHeader​(java.lang.String name,
                              java.lang.String value)
        Deprecated.
        use appropriate methods in ArmoredOutputStream.Builder instead
        Set an additional header entry. The current value(s) will continue to exist together with the new one. Adding a null value has no effect.
        Parameters:
        name - the name of the header entry.
        value - the value of the header entry.
      • beginClearText

        public void beginClearText​(int hashAlgorithm)
                            throws java.io.IOException
        Start a clear text signed message - backwards compatibility.
        Parameters:
        hashAlgorithm - hash algorithm
        Throws:
        java.io.IOException
      • beginClearText

        public void beginClearText​(int... hashAlgorithms)
                            throws java.io.IOException
        Start a clear text signed message.
        Parameters:
        hashAlgorithms - hash algorithms
        Throws:
        java.io.IOException
      • endClearText

        public void endClearText()
      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Note: close() does not close the underlying stream. So it is possible to write multiple objects using armoring to a single stream.
        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