Class CRCingArmoredInputStreamWrapper

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

    public class CRCingArmoredInputStreamWrapper
    extends org.bouncycastle.bcpg.ArmoredInputStream
    Utility class that causes read(bytes, offset, length) to properly throw exceptions caused by faulty CRC checksums. Furthermore, this class swallows exceptions from BC's ArmoredInputStream that are caused by missing CRC checksums.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      java.lang.String getArmorHeaderLine()  
      java.lang.String[] getArmorHeaders()  
      boolean isClearText()  
      boolean isEndOfStream()  
      void mark​(int readlimit)  
      boolean markSupported()  
      static java.io.InputStream possiblyWrap​(java.io.InputStream inputStream)  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)
      Reads up to len bytes of data from the input stream into an array of bytes.
      void reset()  
      long skip​(long n)  
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

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

      • CRCingArmoredInputStreamWrapper

        public CRCingArmoredInputStreamWrapper​(org.bouncycastle.bcpg.ArmoredInputStream inputStream)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • possiblyWrap

        public static java.io.InputStream possiblyWrap​(java.io.InputStream inputStream)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • isClearText

        public boolean isClearText()
        Overrides:
        isClearText in class org.bouncycastle.bcpg.ArmoredInputStream
      • isEndOfStream

        public boolean isEndOfStream()
        Overrides:
        isEndOfStream in class org.bouncycastle.bcpg.ArmoredInputStream
      • getArmorHeaderLine

        public java.lang.String getArmorHeaderLine()
        Overrides:
        getArmorHeaderLine in class org.bouncycastle.bcpg.ArmoredInputStream
      • getArmorHeaders

        public java.lang.String[] getArmorHeaders()
        Overrides:
        getArmorHeaders in class org.bouncycastle.bcpg.ArmoredInputStream
      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class org.bouncycastle.bcpg.ArmoredInputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.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 java.io.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:
        java.io.IOException - if an exception happens AT ANY POINT
        See Also:
        Related BC bug report
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class org.bouncycastle.bcpg.ArmoredInputStream
        Throws:
        java.io.IOException
      • 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 org.bouncycastle.bcpg.ArmoredInputStream
        Throws:
        java.io.IOException
      • mark

        public void mark​(int readlimit)
        Overrides:
        mark in class java.io.InputStream
      • reset

        public void reset()
                   throws java.io.IOException
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.InputStream