|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
it.unimi.dsi.fastutil.io.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 optimise 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 | |
static int |
DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes (8Ki). |
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 java.io.InputStream |
mark, markSupported, read |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_BUFFER_SIZE
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
IOException
public int read(byte[] b, int offset, int length) throws IOException
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
IOException
public int available() throws IOException
IOException
public void close() throws IOException
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).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |