Class LineReader
- java.lang.Object
-
- org.openrefine.runners.local.pll.util.LineReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class LineReader extends Object implements Closeable
A class which reads line by line from anInputStream
, making sure it only reads the bytes it needs to complete the current line.This makes it possible to track at which byte offset each line starts, when used in combination with a
CountingInputStream
(seeTextFilePLL
).This cannot be achieved with
InputStreamReader
andLineNumberReader
, becauseInputStreamReader
can read more bytes than it needs to output characters.Like in
LineNumberReader
, a line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed.TODO: this class is much less efficient than LineNumberReader. We should investigate why.
- Author:
- Antonin Delpeuch
-
-
Field Summary
Fields Modifier and Type Field Description protected Charset
charset
protected InputStream
inputStream
-
Constructor Summary
Constructors Constructor Description LineReader(InputStream inputStream, Charset charset)
Constructs a reader with the supplied input stream and charset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the underlying input stream.String
readLine()
Reads a single line from the input stream, not reading more characters beyond the line being read.
-
-
-
Field Detail
-
inputStream
protected final InputStream inputStream
-
charset
protected final Charset charset
-
-
Constructor Detail
-
LineReader
public LineReader(InputStream inputStream, Charset charset)
Constructs a reader with the supplied input stream and charset.- Parameters:
inputStream
-charset
-
-
-
Method Detail
-
readLine
public String readLine() throws IOException
Reads a single line from the input stream, not reading more characters beyond the line being read.- Returns:
- the line read or null if the input stream was exhausted
- Throws:
IOException
-
close
public void close() throws IOException
Closes the underlying input stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-