Class LineBuffer

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.StringBuilder line
      Holds partial line contents.
      private boolean sawReturn
      Whether a line ending with a CR is pending processing.
    • Constructor Summary

      Constructors 
      Constructor Description
      LineBuffer()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void add​(char[] cbuf, int off, int len)
      Process additional characters from the stream.
      protected void finish()
      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).
      private boolean finishLine​(boolean sawNewline)
      Called when a line is complete.
      protected abstract void handleLine​(java.lang.String line, java.lang.String end)
      Called for each line found in the character data passed to add(char[], int, int).
      • Methods inherited from class java.lang.Object

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

      • line

        private java.lang.StringBuilder line
        Holds partial line contents.
      • sawReturn

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

      • LineBuffer

        LineBuffer()
    • Method Detail

      • add

        protected void add​(char[] cbuf,
                           int off,
                           int len)
                    throws java.io.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:
        java.io.IOException - if an I/O error occurs
        See Also:
        finish()
      • finishLine

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

        protected void finish()
                       throws java.io.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:
        java.io.IOException - if an I/O error occurs
      • handleLine

        protected abstract void handleLine​(java.lang.String line,
                                           java.lang.String end)
                                    throws java.io.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:
        java.io.IOException - if an I/O error occurs