public class LineReader
extends java.lang.Object
implements java.lang.AutoCloseable
\n, linefeeds
\r are ignored.
This is a rather minimal implementation, which supposedly pays off in
performance. In particular, this class allows recycling the buffer, which
will yield less object allocations and thus less garbage collection.
Usage example:
StringBuilder buf = new StringBuilder();
LineReader reader = new LineReader(inputStream);
// Clear buffer, and append next line.
while(reader.readLine(buf.setLength(0))) {
// process string in buffer.
}
| Modifier and Type | Field and Description |
|---|---|
(package private) char[] |
buffer
Character buffer
|
(package private) static int |
BUFFER_SIZE
Default buffer size to use
|
(package private) int |
end
Current position, and length of buffer
|
(package private) java.io.Reader |
in
Input stream to read from
|
(package private) int |
pos
Current position, and length of buffer
|
| Constructor and Description |
|---|
LineReader(java.io.InputStream in)
Constructor
|
LineReader(java.io.InputStream in,
int buffersize)
Constructor
|
LineReader(java.io.Reader in)
Constructor
|
LineReader(java.io.Reader in,
int buffersize)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
readLine(java.lang.Appendable buf)
Read a line into the given buffer.
|
static final int BUFFER_SIZE
java.io.Reader in
char[] buffer
int pos
int end
public LineReader(java.io.InputStream in)
in - Streampublic LineReader(java.io.Reader in)
in - Readerpublic LineReader(java.io.InputStream in,
int buffersize)
in - Readerbuffersize - Buffer sizepublic LineReader(java.io.Reader in,
int buffersize)
in - Readerbuffersize - Buffer sizepublic boolean readLine(java.lang.Appendable buf)
throws java.io.IOException
buf - Buffer.true if some characters have been read.java.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseablejava.io.IOExceptionCopyright © 2019 ELKI Development Team. License information.