public class CircularBufferInputStream extends InputStream
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.
|
protected InputStream |
in
What we are streaming, used to fill the internal buffer.
|
| Constructor and Description |
|---|
CircularBufferInputStream(InputStream inputStream)
Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size
(
IOUtils.DEFAULT_BUFFER_SIZE). |
CircularBufferInputStream(InputStream inputStream,
int bufferSize)
Creates 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[] buffer) |
int |
read(byte[] targetBuffer,
int offset,
int length) |
available, mark, markSupported, reset, skipprotected final InputStream in
protected final CircularByteBuffer buffer
protected final int bufferSize
public CircularBufferInputStream(InputStream inputStream, int bufferSize)
inputStream - The input stream, which is being buffered.bufferSize - The size of the CircularByteBuffer, which is used internally.public CircularBufferInputStream(InputStream inputStream)
IOUtils.DEFAULT_BUFFER_SIZE).inputStream - The input stream, which is being buffered.protected void fillBuffer()
throws IOException
IOException - in case of an error while reading from the input stream.protected boolean haveBytes(int count)
throws IOException
count - number of byte to fill into the bufferIOException - in case of an error while reading from the input stream.public int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] buffer)
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] targetBuffer,
int offset,
int length)
throws IOException
read in class InputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionCopyright © 2002–2021 The Apache Software Foundation. All rights reserved.