Class CircularBufferInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.buffer.CircularBufferInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
PeekableInputStream
Implements a buffered input stream, which is internally based on a
CircularByteBuffer
. Unlike the
BufferedInputStream
, this one doesn't need to reallocate byte arrays internally.- Since:
- 2.7
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CircularByteBuffer
Internal buffer.protected final int
Internal buffer size.Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionCircularBufferInputStream
(InputStream inputStream) Constructs 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) Constructs a new instance, which filters the given input stream, and uses the given buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
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) Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset, skip
-
Field Details
-
buffer
Internal buffer. -
bufferSize
Internal buffer size.
-
-
Constructor Details
-
CircularBufferInputStream
Constructs a new instance, which filters the given input stream, and uses a reasonable default buffer size (IOUtils.DEFAULT_BUFFER_SIZE
).- Parameters:
inputStream
- The input stream, which is being buffered.
-
CircularBufferInputStream
Constructs a new instance, which filters the given input stream, and uses the given buffer size.- Parameters:
inputStream
- The input stream, which is being buffered.bufferSize
- The size of theCircularByteBuffer
, which is used internally.
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-
fillBuffer
Fills the buffer with the contents of the input stream.- Throws:
IOException
- in case of an error while reading from the input stream.
-
haveBytes
Fills the buffer from the input stream until the given number of bytes have been added to the buffer.- Parameters:
count
- number of byte to fill into the buffer- Returns:
- true if the buffer has bytes
- Throws:
IOException
- in case of an error while reading from the input stream.
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-