public class FramedInputStream extends InputStream
The framed input stream reads an entire frame worth of data into its
internal buffer when readFrame() is called. It then
behaves as if this is the only data available on the stream (meaning
that when the data in the frame is exhausted, it will behave as if the
end of the stream has been reached). The buffer can only contain a
single frame at a time, so any data left over from a previous frame
will disappear when readFrame() is called again.
Note: The framing input stream does not synchronize reads from its internal buffer. It is intended to only be accessed from a single thread.
Implementation note: maybe this should derive from
FilterInputStream and be tied to a single
InputStream for its lifetime.
| Constructor and Description |
|---|
FramedInputStream()
Creates a new framed input stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes that can be read from this input stream
without blocking.
|
void |
mark(int readAheadLimit)
Does nothing, as marking is not supported.
|
boolean |
markSupported()
Always returns false as framed input streams do not support
marking.
|
int |
read()
Reads the next byte of data from this input stream.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data into an array of bytes
from this input stream. |
boolean |
readFrame(ReadableByteChannel source)
Reads a frame from the provided channel, appending to any partially
read frame.
|
void |
reset()
Resets the buffer to the beginning of the buffered frames.
|
long |
skip(long n)
Skips
n bytes of input from this input stream. |
close, readpublic boolean readFrame(ReadableByteChannel source) throws IOException
readFrame will return false, otherwise true.
Note: when this method returns true, it is required
that the caller read all of the frame data from the stream
before again calling readFrame(java.nio.channels.ReadableByteChannel) as the previous frame's
data will be elimitated upon the subsequent call.
IOExceptionpublic int read()
int in the range 0 to
255. If no byte is available because the end of the
stream has been reached, the value -1 is returned.
This read method cannot block.
read in class InputStream-1 if the end of the
stream has been reached.public int read(byte[] b,
int off,
int len)
len bytes of data into an array of bytes
from this input stream. If pos equals
count, then -1 is returned to indicate
end of file. Otherwise, the number k of bytes read is
equal to the smaller of len and
count-pos. If k is positive, then bytes
buf[pos] through buf[pos+k-1] are copied
into b[off] through b[off+k-1] in the
manner performed by System.arraycopy. The value
k is added into pos and k is
returned.
This read method cannot block.
read in class InputStreamb - the buffer into which the data is read.off - the start offset of the data.len - the maximum number of bytes read.-1 if there is no more data because the end of the
stream has been reached.public long skip(long n)
n bytes of input from this input stream. Fewer
bytes might be skipped if the end of the input stream is reached.
The actual number k of bytes to be skipped is equal to
the smaller of n and count-pos. The value
k is added into pos and k is
returned.skip in class InputStreamn - the number of bytes to be skipped.public int available()
available in class InputStreampublic boolean markSupported()
markSupported in class InputStreampublic void mark(int readAheadLimit)
mark in class InputStreampublic void reset()
reset in class InputStreamCopyright © 2015. All rights reserved.