public class CircularBufferInputStream
extends java.io.FilterInputStream
CircularByteBuffer. Unlike the
BufferedInputStream, this one doesn't need to reallocate byte arrays internally.| Modifier and Type | Field and Description |
|---|---|
protected CircularByteBuffer |
buffer
Internal buffer.
|
protected int |
bufferSize
Internal buffer size.
|
private boolean |
eof
Whether we've seen the input stream EOF.
|
| Constructor and Description |
|---|
CircularBufferInputStream(java.io.InputStream inputStream)
Constructs a new instance, which filters the given input stream, and uses a reasonable default buffer size
(
IOUtils.DEFAULT_BUFFER_SIZE). |
CircularBufferInputStream(java.io.InputStream inputStream,
int bufferSize)
Constructs a new instance, which filters the given input stream, and uses the given buffer size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected void |
fillBuffer()
Fills the buffer with the contents of the input stream.
|
protected boolean |
haveBytes(int count)
Fills the buffer from the input stream until the given number of bytes have been added to the buffer.
|
int |
read() |
int |
read(byte[] targetBuffer,
int offset,
int length) |
protected final CircularByteBuffer buffer
protected final int bufferSize
private boolean eof
public CircularBufferInputStream(java.io.InputStream inputStream)
IOUtils.DEFAULT_BUFFER_SIZE).inputStream - The input stream, which is being buffered.public CircularBufferInputStream(java.io.InputStream inputStream,
int bufferSize)
inputStream - The input stream, which is being buffered.bufferSize - The size of the CircularByteBuffer, which is used internally.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterInputStreamjava.io.IOExceptionprotected void fillBuffer()
throws java.io.IOException
java.io.IOException - in case of an error while reading from the input stream.protected boolean haveBytes(int count)
throws java.io.IOException
count - number of byte to fill into the bufferjava.io.IOException - in case of an error while reading from the input stream.public int read()
throws java.io.IOException
read in class java.io.FilterInputStreamjava.io.IOExceptionpublic int read(byte[] targetBuffer,
int offset,
int length)
throws java.io.IOException
read in class java.io.FilterInputStreamjava.io.IOException