|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectInputStream
FastBufferedInputStream
public class FastBufferedInputStream
Lightweight, unsynchronised, aligned input stream buffering class.
This class provides buffering for input streams, but it does so with purposes
and an internal logic that are radically different from the ones adopted in
BufferedInputStream
.
There is no support for marking. All methods are unsychronised. Moreover, it is guaranteed that all reads performed by this class will be multiples of the given buffer size. If, for instance, you use the default buffer size, reads will be performed on the underlying input stream in multiples of 16384 bytes. This is very important on operating systems that optimize disk reads on disk block boundaries.
As an additional feature, this class implements the RepositionableStream
interface. An instance of this class will try to cast
the underlying byte stream to a RepositionableStream
and to fetch by
reflection the FileChannel
underlying the given
output stream, in this order. If either reference can be successfully
fetched, you can use position(long)
to reposition the stream. Note
that even in this case, it is still guaranteed that all reads will be
performed on buffer boundaries, that is, as if the stream was divided in
blocks of the size of the buffer.
Field Summary | |
---|---|
protected int |
avail
The number of buffer bytes available starting from pos . |
protected byte[] |
buffer
The internal buffer. |
static int |
DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes (8Ki). |
protected InputStream |
is
The underlying input stream. |
protected int |
pos
The current position in the buffer. |
Constructor Summary | |
---|---|
FastBufferedInputStream(InputStream is)
Creates a new fast buffered input stream by wrapping a given input stream with a buffer of DEFAULT_BUFFER_SIZE bytes. |
|
FastBufferedInputStream(InputStream is,
int bufSize)
Creates a new fast buffered input stream by wrapping a given input stream with a given buffer size. |
Method Summary | |
---|---|
int |
available()
|
void |
close()
|
long |
position()
Returns the current stream position. |
void |
position(long newPosition)
Sets the current stream position. |
int |
read()
|
int |
read(byte[] b,
int offset,
int length)
|
void |
reset()
Resets the internal logic of this fast buffered input stream, clearing the buffer. |
long |
skip(long n)
|
Methods inherited from class InputStream |
---|
mark, markSupported, read |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_BUFFER_SIZE
protected InputStream is
protected byte[] buffer
protected int pos
protected int avail
pos
.
Constructor Detail |
---|
public FastBufferedInputStream(InputStream is, int bufSize)
is
- an input stream to wrap.bufSize
- the size in bytes of the internal buffer.public FastBufferedInputStream(InputStream is)
DEFAULT_BUFFER_SIZE
bytes.
is
- an input stream to wrap.Method Detail |
---|
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int offset, int length) throws IOException
read
in class InputStream
IOException
public void position(long newPosition) throws IOException
RepositionableStream
position
in interface RepositionableStream
newPosition
- the new stream position.
IOException
public long position() throws IOException
RepositionableStream
position
in interface RepositionableStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
public void reset()
The underlying input stream is not modified, but its position cannot be easily predicted, due to buffering. This method is thus mainly useful for reading files that are being written by other process (in practice, it makes the current buffer invalid).
reset
in class InputStream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |