public class LineReader extends Object implements 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.delete(0, buf.length()))) { // process string in buffer. }
Modifier and Type | Field and Description |
---|---|
(package private) char[] |
buffer
Character buffer
|
(package private) static int |
BUFFER_SIZE
Buffer size to use
|
(package private) int |
end
Current position, and length of buffer
|
(package private) Reader |
in
Input stream to read from
|
(package private) int |
pos
Current position, and length of buffer
|
Constructor and Description |
---|
LineReader(InputStream in)
Constructor
|
LineReader(Reader in)
Constructor
|
static final int BUFFER_SIZE
Reader in
char[] buffer
int pos
int end
public LineReader(InputStream in)
in
- Streampublic LineReader(Reader in)
in
- Readerpublic boolean readLine(Appendable buf) throws IOException
buf
- Buffer.true
if some characters have been read.IOException
public void close() throws IOException
close
in interface AutoCloseable
IOException
Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.