Class CircularBufferInputStream
java.lang.Object
java.io.InputStream
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CircularByteBuffer
Internal buffer.protected final int
Internal buffer size.protected final InputStream
What we are streaming, used to fill the internal buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCircularBufferInputStream
(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. -
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[] buffer) int
read
(byte[] targetBuffer, int offset, int length) Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
in
What we are streaming, used to fill the internal buffer. -
buffer
Internal buffer. -
bufferSize
Internal buffer size.
-
-
Constructor Details
-
CircularBufferInputStream
Creates 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.
-
CircularBufferInputStream
Creates 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.
-
-
Method Details
-
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
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-