Class LineBuffer

java.lang.Object
com.google.common.io.LineBuffer

abstract class LineBuffer extends Object
Package-protected abstract class that implements the line reading algorithm used by LineReader. Line separators are per BufferedReader: line feed, carriage return, or carriage return followed immediately by a linefeed.

Subclasses must implement handleLine(java.lang.String, java.lang.String), call add(char[], int, int) to pass character data, and call finish() at the end of stream.

Since:
1.0
  • Field Details

    • line

      private StringBuilder line
      Holds partial line contents.
    • sawReturn

      private boolean sawReturn
      Whether a line ending with a CR is pending processing.
  • Constructor Details

    • LineBuffer

      LineBuffer()
  • Method Details

    • add

      protected void add(char[] cbuf, int off, int len) throws IOException
      Process additional characters from the stream. When a line separator is found the contents of the line and the line separator itself are passed to the abstract handleLine(java.lang.String, java.lang.String) method.
      Parameters:
      cbuf - the character buffer to process
      off - the offset into the buffer
      len - the number of characters to process
      Throws:
      IOException - if an I/O error occurs
      See Also:
    • finishLine

      private boolean finishLine(boolean sawNewline) throws IOException
      Called when a line is complete.
      Throws:
      IOException
    • finish

      protected void finish() throws IOException
      Subclasses must call this method after finishing character processing, in order to ensure that any unterminated line in the buffer is passed to handleLine(java.lang.String, java.lang.String).
      Throws:
      IOException - if an I/O error occurs
    • handleLine

      protected abstract void handleLine(String line, String end) throws IOException
      Called for each line found in the character data passed to add(char[], int, int).
      Parameters:
      line - a line of text (possibly empty), without any line separators
      end - the line separator; one of "\r", "\n", "\r\n", or ""
      Throws:
      IOException - if an I/O error occurs