Class LineReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class LineReader
    extends java.lang.Object
    implements java.io.Closeable
    Reads lines from a reader like BufferedReader but also returns the line terminators.

    Line terminators can be either a line feed "\n", carriage return "\r", or a carriage return followed by a line feed "\r\n". Call getLineTerminator() after readLine() to obtain the corresponding line terminator. If a stream has a line at the end without a terminator, getLineTerminator() returns null.

    • Constructor Summary

      Constructors 
      Constructor Description
      LineReader​(java.io.Reader reader)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      private void fill()  
      private java.lang.String finish​(java.lang.StringBuilder sb, int start, int end)  
      java.lang.String getLineTerminator()
      Return the line terminator of the last read line from readLine().
      private java.lang.String line​(java.lang.String line, java.lang.String lineTerminator)  
      java.lang.String readLine()
      Read a line of text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • reader

        private java.io.Reader reader
      • cbuf

        private char[] cbuf
      • position

        private int position
      • limit

        private int limit
      • lineTerminator

        private java.lang.String lineTerminator
    • Constructor Detail

      • LineReader

        public LineReader​(java.io.Reader reader)
    • Method Detail

      • readLine

        public java.lang.String readLine()
                                  throws java.io.IOException
        Read a line of text.
        Returns:
        the line, or null when the end of the stream has been reached and no more lines can be read
        Throws:
        java.io.IOException
      • getLineTerminator

        public java.lang.String getLineTerminator()
        Return the line terminator of the last read line from readLine().
        Returns:
        "\n", "\r", "\r\n", or null
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • fill

        private void fill()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • line

        private java.lang.String line​(java.lang.String line,
                                      java.lang.String lineTerminator)
      • finish

        private java.lang.String finish​(java.lang.StringBuilder sb,
                                        int start,
                                        int end)