Class StrictLineReader

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

    
    public class StrictLineReader
     implements Closeable
                        

    Buffers input from an InputStream for reading lines.

    This class is used for buffered reading of lines. For purposes of this class, a line ends with "\n" or "\r\n". End of input is reported by throwing EOFException. Unterminated line at end of input is invalid and will be ignored, the caller may use hasUnterminatedLine() to detect it after catching the EOFException.

    This class is intended for reading input that strictly consists of lines, such as line-based cache entries or cache journal. Unlike the java.io.BufferedReader which in conjunction with java.io.InputStreamReader provides similar functionality, this class uses different end-of-input reporting and a more restrictive definition of a line.

    This class supports only charsets that encode '\r' and '\n' as a single byte with value 13 and 10, respectively, and the representation of no other character contains these values. We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1. The default charset is US_ASCII.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      void close() Closes the reader by closing the underlying InputStream and marking this reader as closed.
      String readLine() Reads the next line.
      • Methods inherited from class java.lang.Object

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

      • StrictLineReader

        StrictLineReader(InputStream in, Charset charset)
        Constructs a new LineReader with the specified charset and the default capacity.
        Parameters:
        in - the InputStream to read data from.
        charset - the charset used to decode data.
      • StrictLineReader

        StrictLineReader(InputStream in, int capacity, Charset charset)
        Constructs a new LineReader with the specified capacity and charset.
        Parameters:
        in - the InputStream to read data from.
        capacity - the capacity of the buffer.
        charset - the charset used to decode data.
    • Method Detail

      • close

         void close()

        Closes the reader by closing the underlying InputStream and marking this reader as closed.

      • readLine

         String readLine()

        Reads the next line. A line ends with "\n" or "\r\n", this end of line marker is not included in the result.

        Returns:

        the next line from the input.