Package org.bouncycastle.openpgp.api
Class DoubleBufferedInputStream<I extends InputStream>
java.lang.Object
java.io.InputStream
org.bouncycastle.openpgp.api.DoubleBufferedInputStream<I>
- All Implemented Interfaces:
Closeable
,AutoCloseable
Implementation of an
InputStream
that double-buffers data from an underlying input stream.
Upon reaching the end of the underlying data stream, the underlying data stream is
automatically closed.
Any exceptions while reading from the underlying input stream cause the DoubleBufferedInputStream
to withhold pending data.
This is done in order to minimize the risk of emitting unauthenticated plaintext, while at the same
time being somewhat resource-efficient.
The minimum number of bytes to withhold can be configured (BUFFER_SIZE
by default).-
Constructor Summary
ConstructorsConstructorDescriptionCreate aDoubleBufferedInputStream
, which buffers twice 32MiB.DoubleBufferedInputStream
(I in, int bufferSize) Create aDoubleBufferedInputStream
, which buffers twice the given buffer size in bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Return the underlyingInputStream
.int
read()
int
read
(byte[] b, int off, int len) Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
DoubleBufferedInputStream
Create aDoubleBufferedInputStream
, which buffers twice 32MiB.- Parameters:
in
- input stream
-
DoubleBufferedInputStream
Create aDoubleBufferedInputStream
, which buffers twice the given buffer size in bytes.- Parameters:
in
- input streambufferSize
- buffer size
-
-
Method Details
-
getInputStream
Return the underlyingInputStream
.- Returns:
- underlying input stream
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-