Package elki.utilities.io
Class BufferedLineReader
- java.lang.Object
-
- elki.utilities.io.BufferedLineReader
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
TokenizedReader
public class BufferedLineReader extends java.lang.Object implements java.lang.AutoCloseableClass for buffered IO, avoiding some of the overheads of the Java API.The main difference to the standard Java API is that this implementation will reuse the buffer. After a call to
nextLine(), the buffer will be overwitten!- Since:
- 0.7.0
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringBuilderbufThe buffer we read the data into.protected intlineNumberCurrent line number.private LineReaderreaderLine reader.
-
Constructor Summary
Constructors Constructor Description BufferedLineReader()Constructor.BufferedLineReader(LineReader in)Constructor.BufferedLineReader(java.io.InputStream in)Constructor.BufferedLineReader(java.io.InputStreamReader in)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.lang.CharSequencegetBuffer()Get the reader buffer.intgetLineNumber()Get the current line number.static intlengthWithoutLinefeed(java.lang.CharSequence line)Get the length of the string, not taking trailing linefeeds into account.booleannextLine()Read the next line.voidreset()Reset the current reader (but do not close the stream).voidreset(LineReader r)Reset to a new line reader.voidreset(java.io.InputStream in)Reset to a new line reader.voidreset(java.io.InputStreamReader in)Reset to a new line reader.
-
-
-
Field Detail
-
reader
private LineReader reader
Line reader.
-
buf
protected java.lang.StringBuilder buf
The buffer we read the data into.
-
lineNumber
protected int lineNumber
Current line number.
-
-
Constructor Detail
-
BufferedLineReader
public BufferedLineReader()
Constructor. Usereset()to assign an input stream.
-
BufferedLineReader
public BufferedLineReader(LineReader in)
Constructor.- Parameters:
in- Line reader
-
BufferedLineReader
public BufferedLineReader(java.io.InputStream in)
Constructor.- Parameters:
in- Input stream
-
BufferedLineReader
public BufferedLineReader(java.io.InputStreamReader in)
Constructor.- Parameters:
in- Input stream reader
-
-
Method Detail
-
reset
public void reset()
Reset the current reader (but do not close the stream).
-
reset
public void reset(LineReader r)
Reset to a new line reader.A previous reader will not be closed automatically!
- Parameters:
r- New reader
-
reset
public void reset(java.io.InputStream in)
Reset to a new line reader.A previous stream will not be closed automatically!
- Parameters:
in- New input stream reader
-
reset
public void reset(java.io.InputStreamReader in)
Reset to a new line reader.A previous stream will not be closed automatically!
- Parameters:
in- New input stream reader
-
getBuffer
public java.lang.CharSequence getBuffer()
Get the reader buffer.After a call to
nextLine(), the buffer will be overwitten!- Returns:
- Buffer.
-
getLineNumber
public int getLineNumber()
Get the current line number.- Returns:
- Current line number
-
nextLine
public boolean nextLine() throws java.io.IOExceptionRead the next line.- Returns:
trueif another line was read successfully.- Throws:
java.io.IOException- on IO errors.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
lengthWithoutLinefeed
public static int lengthWithoutLinefeed(java.lang.CharSequence line)
Get the length of the string, not taking trailing linefeeds into account.- Parameters:
line- Input line- Returns:
- Length
-
-