Package org.bouncycastle.bcpg
Class ArmoredInputStream
java.lang.Object
java.io.InputStream
org.bouncycastle.bcpg.ArmoredInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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);
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionCreate a stream for reading a PGP armoured message, parsing up to a header and then reading the data that follows.ArmoredInputStream
(InputStream in, boolean hasHeaders) Create an armoured input stream which will assume the data starts straight away, or parse for headers first depending on the value of hasHeaders. -
Method Summary
Modifier and TypeMethodDescriptionint
static ArmoredInputStream.Builder
builder()
void
close()
Return the armor header line (if there is one)String[]
Return the armor headers (the lines after the armor header line),boolean
boolean
int
read()
int
read
(byte[] b, int off, int len) Reads up tolen
bytes of data from the input stream into an array of bytes.void
setDetectMissingCRC
(boolean detectMissing) Deprecated.use Builder class for configuring this.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
ArmoredInputStream
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
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
- Overrides:
available
in classInputStream
- 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
Return the armor header line (if there is one)- Returns:
- the armor header line, null if none present.
-
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
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
Reads up tolen
bytes of data from the input stream into an array of bytes. An attempt is made to read as many aslen
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 elementb[off]
, the next one intob[off+1]
, and so on. The number of bytes read is, at most, equal tolen
. NOTE: We need to override the custom behavior of Java'sInputStream.read(byte[], int, int)
, as the upstream method silently swallowsIOExceptions
. This would cause CRC checksum errors to go unnoticed.- Overrides:
read
in classInputStream
- Parameters:
b
- byte arrayoff
- offset at which we start writing data to the arraylen
- 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
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- 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, anIOException
will be thrown if a missing CRC checksum is encountered.- Parameters:
detectMissing
- false if ignore missing CRC sums, true for exception
-
builder
-