Package org.pgpainless.util

# Class CRCingArmoredInputStreamWrapper

java.lang.Object
java.io.InputStream
org.bouncycastle.bcpg.ArmoredInputStream
org.pgpainless.util.CRCingArmoredInputStreamWrapper

All Implemented Interfaces:
  `Closeable`, `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.

## Nested Class Summary

## Nested classes/interfaces inherited from class org.bouncycastle.bcpg.ArmoredInputStream

`org.bouncycastle.bcpg.ArmoredInputStream.Builder`

## Constructor Summary

Constructors
Constructor
Description
`CRCingArmoredInputStreamWrapper(org.bouncycastle.bcpg.ArmoredInputStream inputStream)`

## Method Summary

Modifier and Type
Method
Description
`int`
`available()`
`void`
`close()`
`String`
`getArmorHeaderLine()`
`String[]`
`getArmorHeaders()`
`boolean`
`isClearText()`
`boolean`
`isEndOfStream()`
`void`
`mark(int readlimit)`
`boolean`
`markSupported()`
`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 org.bouncycastle.bcpg.ArmoredInputStream

`builder, setDetectMissingCRC`

### Methods inherited from class java.io.InputStream

`nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CRCingArmoredInputStreamWrapper

public CRCingArmoredInputStreamWrapper(org.bouncycastle.bcpg.ArmoredInputStream inputStream) throws IOException

Throws:
  `IOException`

## Method Details

### 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 String getArmorHeaderLine()

Overrides:
  `getArmorHeaderLine` in class `org.bouncycastle.bcpg.ArmoredInputStream`

### getArmorHeaders

public String[] getArmorHeaders()

Overrides:
  `getArmorHeaders` in class `org.bouncycastle.bcpg.ArmoredInputStream`

### read

public int read() throws IOException

Overrides:
  `read` in class `org.bouncycastle.bcpg.ArmoredInputStream`
Throws:
  `IOException`

### read

public int read(@Nonnull byte[] b) throws IOException

Overrides:
  `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 `org.bouncycastle.bcpg.ArmoredInputStream`
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:
  - Related BC bug report

### skip

public long skip(long n) throws IOException

Overrides:
  `skip` in class `InputStream`
Throws:
  `IOException`

### available

public int available() throws IOException

Overrides:
  `available` in class `org.bouncycastle.bcpg.ArmoredInputStream`
Throws:
  `IOException`

### close

public void close() throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `org.bouncycastle.bcpg.ArmoredInputStream`
Throws:
  `IOException`

### mark

public void mark(int readlimit)

Overrides:
  `mark` in class `InputStream`

### reset

public void reset() throws IOException

Overrides:
  `reset` in class `InputStream`
Throws:
  `IOException`

### markSupported

public boolean markSupported()

Overrides:
  `markSupported` in class `InputStream`