Package org.bzdev.io

Class LineReader

All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class LineReader extends BufferedReader
Buffered reader with a choice of line terminations.

When a constructor specifies a delimiter, and that delimiter is not null, the method readLine() will assume that an end of line is represented by either a line feed, a carriage return, or a carriage return followed by a line feed, with the delimiter specifying which of these combinations represents the end of a line. If the delimiter is null (the default), the behavior is identical to that for BufferedReader and any of these will indicate an end of line. When a line feed or carriage return does not denote an end of line, that line feed or carriage return will be kept as part of the line.

The behavior for BufferedReader is appropriate when one is reading text files that may have been generated on systems using differing, but common, end-of-line conventions. LineReader with an explicit delimiter choice is useful when processing files that conform to standards that specify specific line-termination sequences, and where characters that are not part of that sequence should be kept as is.

To specify a character encoding, the Reader passed as the first argument of a constructor should be an instance of InputStreamReader or a Reader that contains an instance of InputStreamReader, possibly with several intermediate readers.

  • Constructor Details

  • Method Details

    • readLine

      public String readLine() throws IOException
      Read a line of text. When the constructor provides a delimiter, that delimiter is the one that will be used, and the other end-of-line characters are treated as characters within the line. If the delimiter is null (the default), the behavior is identical to that for BufferedReader.
      Overrides:
      readLine in class BufferedReader
      Returns:
      a line of text; null if the end of the file has been reached
      Throws:
      IOException - an IO error occurred