public class BufferInputStream extends InputStream implements ByteProcessable
InputStream that works like a BufferedInputStream but exposes its
internal state to be used for lookahead operations. | Modifier and Type | Class and Description |
|---|---|
protected static class |
BufferInputStream.CopyProcessor
This inner class is the
ByteProcessor used to copy bytes from the buffer to the caller consuming data from
this stream. |
| Modifier and Type | Field and Description |
|---|---|
private ByteArrayBufferBuffer |
buffer
the internal buffer.
|
private BufferInputStream.CopyProcessor |
copyProcessor
The processor used to copy the bytes from the
buffer to the readers buffer. |
private static int |
DEFAULT_CAPACITY
The default capacity used by
BufferInputStream(InputStream). |
private boolean |
eos
true if the end of the stream has been reached, false otherwise. |
private InputStream |
inStream
|
| Modifier | Constructor and Description |
|---|---|
|
BufferInputStream(InputStream inStream)
The constructor.
|
|
BufferInputStream(InputStream inStream,
int capacity)
The constructor.
|
private |
BufferInputStream(InputStream inStream,
int capacity,
int bufferCount)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
ProcessableByteArrayBuffer |
createLookaheadBuffer()
This method creates a new
buffer for lookahead operations on the data from the
underlying stream. |
protected void |
ensureOpen()
This method ensures that this stream has NOT been
closed. |
boolean |
fill()
This method (re-)fills the internal buffer as far as data is available from the underlying
InputStream
without consuming data from the stream. |
long |
process(ByteProcessor processor,
long length)
This method processes the number of bytes given by
length (as far as available) using the given
processor. |
int |
read() |
int |
read(byte[] bytes,
int offset,
int length) |
long |
skip(long skipCount) |
mark, markSupported, read, resetprivate static final int DEFAULT_CAPACITY
BufferInputStream(InputStream).private InputStream inStream
private final ByteArrayBufferBuffer buffer
private boolean eos
true if the end of the stream has been reached, false otherwise.private BufferInputStream.CopyProcessor copyProcessor
buffer to the readers buffer.public BufferInputStream(InputStream inStream)
inStream - is the InputStream to adapt.public BufferInputStream(InputStream inStream, int capacity)
inStream - is the InputStream to adapt.capacity - is the capacity for each of the two ByteArrayBufferImpl s. Please note that therefore the
double amount of memory is allocated.private BufferInputStream(InputStream inStream, int capacity, int bufferCount)
inStream - is the InputStream to adapt.capacity - is the capacity for each of the two ByteArrayBufferImpl s. Please note that therefore the
double amount of memory is allocated.bufferCount - is the number of buffers to use.protected void ensureOpen()
throws IOException
closed.IOException - if this stream has been closed.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic boolean fill()
throws IOException
InputStream
without consuming data from the stream. If the internal buffer is already filled, the call of this
method will have no effect. true if the end of the stream was encountered while (re)filling the internal buffer, false
otherwise.IOException - if the operation fails.public long skip(long skipCount)
throws IOException
skip in class InputStreamIOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] bytes,
int offset,
int length)
throws IOException
read in class InputStreamIOExceptionpublic int available()
throws IOException
available in class InputStreamIOExceptionpublic long process(ByteProcessor processor, long length)
ByteProcessablelength (as far as available) using the given
processor.process in interface ByteProcessableprocessor - is the ByteProcessor called to process the bytes. It may be called multiple types if the
data is sliced into multiple byte-arrays.length - is the desired number of bytes to process. The value has to be greater or equal to 0. A value
of 0 will have no effect. If you want to process all available data to the end of stream or buffer
you may use Long.MAX_VALUE.length this will typically
be equal to length. However if the end of the data has been reached, a smaller value is returned.
The value will always be greater or equal to 0.public ProcessableByteArrayBuffer createLookaheadBuffer()
buffer for lookahead operations on the data from the
underlying stream. That buffer is a view on the internal buffer of this stream with its own state for the read
position. Consuming data from that buffer will NOT influence the state of this buffer, while consuming data from
this stream will refill the returned buffer.Copyright © 2001–2016 mmm-Team. All rights reserved.