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 |
protected int |
bufferSize |
protected InputStream |
in |
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, skip
protected 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 InputStream
IOException
public int read(byte[] buffer) throws IOException
read
in class InputStream
IOException
public int read(byte[] targetBuffer, int offset, int length) throws IOException
read
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.