Class ArmoredInputStream

java.lang.Object
java.io.InputStream
org.bouncycastle.bcpg.ArmoredInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class ArmoredInputStream extends InputStream
reader for Base64 armored objects - read the headers and then start returning bytes when the data is reached. An IOException is thrown if the CRC check is detected and fails.

By default a missing CRC will not cause an exception. To force CRC detection use:

     ArmoredInputStream aIn = ...

     aIn.setDetectMissingCRC(true);
 

  • Constructor Details

    • ArmoredInputStream

      public ArmoredInputStream(InputStream in) throws IOException
      Create a stream for reading a PGP armoured message, parsing up to a header and then reading the data that follows.
      Parameters:
      in -
      Throws:
      IOException
    • ArmoredInputStream

      public ArmoredInputStream(InputStream in, boolean hasHeaders) throws IOException
      Create an armoured input stream which will assume the data starts straight away, or parse for headers first depending on the value of hasHeaders.
      Parameters:
      in -
      hasHeaders - true if headers are to be looked for, false otherwise.
      Throws:
      IOException
  • Method Details

    • available

      public int available() throws IOException
      Overrides:
      available in class InputStream
      Throws:
      IOException
    • isClearText

      public boolean isClearText()
      Returns:
      true if we are inside the clear text section of a PGP signed message.
    • isEndOfStream

      public boolean isEndOfStream()
      Returns:
      true if the stream is actually at end of file.
    • getArmorHeaderLine

      public String getArmorHeaderLine()
      Return the armor header line (if there is one)
      Returns:
      the armor header line, null if none present.
    • getArmorHeaders

      public String[] getArmorHeaders()
      Return the armor headers (the lines after the armor header line),
      Returns:
      an array of armor headers, null if there aren't any.
    • read

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

      public int read(byte[] b, int off, int len) throws IOException
      Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer. The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. NOTE: We need to override the custom behavior of Java's InputStream.read(byte[], int, int), as the upstream method silently swallows IOExceptions. This would cause CRC checksum errors to go unnoticed.
      Overrides:
      read in class InputStream
      Parameters:
      b - byte array
      off - offset at which we start writing data to the array
      len - number of bytes we write into the array
      Returns:
      total number of bytes read into the buffer
      Throws:
      IOException - if an exception happens AT ANY POINT
      See Also:
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • setDetectMissingCRC

      public void setDetectMissingCRC(boolean detectMissing)
      Deprecated.
      use Builder class for configuring this.
      Change how the stream should react if it encounters missing CRC checksum. The default value is false (ignore missing CRC checksums). If the behavior is set to true, an IOException will be thrown if a missing CRC checksum is encountered.
      Parameters:
      detectMissing - false if ignore missing CRC sums, true for exception
    • builder

      public static ArmoredInputStream.Builder builder()