Class LineReader

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class LineReader
    extends Object
    implements Closeable
    A class which reads line by line from an InputStream, 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 (see TextFilePLL).

    This cannot be achieved with InputStreamReader and LineNumberReader, because InputStreamReader 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 Detail

      • 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