|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Reader
it.unimi.dsi.mg4j.io.FastBufferedReader
Lightweight, unsynchronised, aligned reader buffering class.
This class provides buffering for readers, but it does so with
purposes and an internal logic that are radically different from the ones
adopted in BufferedReader
.
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.
Field Summary | |
protected int |
avail
The number of buffer bytes available starting from pos . |
protected char[] |
buffer
The internal buffer. |
static int |
DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes (16Ki). |
protected int |
pos
The current position in the buffer. |
protected Reader |
r
The underlying reader. |
Fields inherited from class java.io.Reader |
lock |
Constructor Summary | |
FastBufferedReader(Reader r)
Creates a new fast buffered reader by wrapping a given reader with a buffer of DEFAULT_BUFFER_SIZE characters. |
|
FastBufferedReader(Reader r,
int bufSize)
Creates a new fast buffered reder by wrapping a given reder with a given buffer size. |
Method Summary | |
void |
close()
|
int |
read()
|
int |
read(char[] b,
int offset,
int length)
|
MutableString |
readLine(MutableString s)
Reads a line into the given mutable string. |
int |
readWord(MutableString s)
Reads a word into the given mutable string. |
long |
skip(long n)
|
Methods inherited from class java.io.Reader |
mark, markSupported, read, ready, 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 char[] buffer
protected int pos
protected int avail
pos
.
protected Reader r
Constructor Detail |
public FastBufferedReader(Reader r, int bufSize)
r
- a reader to wrap.bufSize
- the size in bytes of the internal buffer.public FastBufferedReader(Reader r)
DEFAULT_BUFFER_SIZE
characters.
r
- a reader to wrap.Method Detail |
public int read() throws IOException
IOException
public int read(char[] b, int offset, int length) throws IOException
IOException
public MutableString readLine(MutableString s) throws IOException
The next line of input (defined as in BufferedReader.readLine()
)
will be stored into s
. Note that if s
is
not loose
this method will be quite inefficient.
s
- a mutable string that will be used to store the next line (which could be empty).
s
or null
if the end of file was found.
IOException
public int readWord(MutableString s) throws IOException
The next word of input (defined as a maximal sequence of characters
satisfying Character.isLetterOrDigit(char)
)
will be stored into s
, and the delimiting character will
be returned. Note that if s
is not
loose
this method will be quite inefficient.
s
- a mutable string that will be used to store the next word (which will be empty
if the next character is not a letter or a digit).
IOException
public long skip(long n) 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 |