|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
it.unimi.dsi.mg4j.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 | |
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 (16Ki). |
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)
|
long |
skip(long n)
|
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 |
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
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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |