|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
net.sf.mmm.util.io.impl.BufferInputStream
public class BufferInputStream
This class represents a InputStream
that works like a
BufferedInputStream
but exposes its internal state to be used
for lookahead operations.
ATTENTION:
This class is intended for internal usage only.
Nested Class Summary | |
---|---|
protected static class |
BufferInputStream.CopyProcessor
This inner class is the ByteProcessor used to copy bytes from the
buffer to the caller consuming data from this stream. |
Field Summary | |
---|---|
private ByteArrayBufferBuffer |
buffer
the internal buffer. |
private BufferInputStream.CopyProcessor |
copyProcessor
The processor used to copy the bytes from the buffer to the
readers buffer. |
private static int |
DEFAULT_CAPACITY
The default capacity used by BufferInputStream(InputStream) . |
private boolean |
eos
true if the end of the stream has been reached,
false otherwise. |
private InputStream |
inStream
The adapted InputStream to buffer or null if
closed . |
Constructor Summary | |
---|---|
|
BufferInputStream(InputStream inStream)
The constructor. |
|
BufferInputStream(InputStream inStream,
int capacity)
The constructor. |
private |
BufferInputStream(InputStream inStream,
int capacity,
int bufferCount)
The constructor. |
Method Summary | |
---|---|
int |
available()
|
void |
close()
|
ProcessableByteArrayBuffer |
createLookaheadBuffer()
This method creates a new buffer for
lookahead operations on the data from the underlying stream. |
protected void |
ensureOpen()
This method ensures that this stream has NOT been closed . |
boolean |
fill()
This method (re-)fills the internal buffer as far as data is available from the underlying InputStream without consuming data
from the stream. |
long |
process(ByteProcessor processor,
long length)
This method processes the number of bytes given by length (as
far as available) using the given processor . |
int |
read()
|
int |
read(byte[] bytes,
int offset,
int length)
|
long |
skip(long skipCount)
|
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, read, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int DEFAULT_CAPACITY
BufferInputStream(InputStream)
.
private InputStream inStream
InputStream
to buffer or null
if
closed
.
private final ByteArrayBufferBuffer buffer
private boolean eos
true
if the end of the stream has been reached,
false
otherwise.
private BufferInputStream.CopyProcessor copyProcessor
buffer
to the
readers buffer.
Constructor Detail |
---|
public BufferInputStream(InputStream inStream)
inStream
- is the InputStream
to adapt.public BufferInputStream(InputStream inStream, int capacity)
inStream
- is the InputStream
to adapt.capacity
- is the capacity for each of the two
ByteArrayBufferImpl
s. Please note that therefore the double
amount of memory is allocated.private BufferInputStream(InputStream inStream, int capacity, int bufferCount)
inStream
- is the InputStream
to adapt.capacity
- is the capacity for each of the two
ByteArrayBufferImpl
s. Please note that therefore the double
amount of memory is allocated.bufferCount
- is the number of buffers to use.Method Detail |
---|
protected void ensureOpen() throws IOException
closed
.
IOException
- if this stream has been closed
.public void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
public boolean fill() throws IOException
InputStream
without consuming
data
from the stream. If the internal buffer is already filled, the call of this
method will have no effect.
true
if the end of the stream was encountered while
(re)filling the internal buffer, false
otherwise.
IOException
- if the operation fails.public long skip(long skipCount) throws IOException
skip
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] bytes, int offset, int length) throws IOException
read
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public long process(ByteProcessor processor, long length)
length
(as
far as available) using the given processor
.
process
in interface ByteProcessable
processor
- is the ByteProcessor
called to process the bytes.
It may be called multiple types if the data is sliced into multiple
byte-arrays.length
- is the desired number of bytes to process. The value has to
be greater or equal to 0
. A value of 0
will have no effect. If you want to process all available data to
the end of stream or buffer you may use Long.MAX_VALUE
.
length
this will typically be equal to
length
. However if the end of the data has been
reached, a smaller value is returned. The value will always be
greater or equal to 0
.public ProcessableByteArrayBuffer createLookaheadBuffer()
buffer
for
lookahead operations on the data from the underlying stream. That buffer is
a view on the internal buffer of this stream with its own state for the
read position. Consuming data from that buffer will NOT influence the state
of this buffer, while consuming data from this stream will refill the
returned buffer.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |