Class ArmoredOutputStream

java.lang.Object
java.io.OutputStream
org.bouncycastle.bcpg.ArmoredOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ArmoredOutputStream extends 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.

  • Field Details

  • Constructor Details

    • ArmoredOutputStream

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

      public ArmoredOutputStream(OutputStream out, Hashtable 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 Details

    • setHeader

      public void setHeader(String name, String value)
      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

      public void clearHeaders()
      Remove all headers.
    • addHeader

      public void addHeader(String name, String value)
      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.
    • resetHeaders

      public void resetHeaders()
      Reset the headers to only contain a Version string (if one is present)
    • beginClearText

      public void beginClearText(int hashAlgorithm) throws IOException
      Start a clear text signed message.
      Parameters:
      hashAlgorithm -
      Throws:
      IOException
    • endClearText

      public void endClearText()
    • write

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

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

      public void close() throws 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 AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException