Package com.google.common.io
Class LineBuffer
java.lang.Object
com.google.common.io.LineBuffer
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 Summary
FieldsModifier and TypeFieldDescriptionprivate StringBuilder
Holds partial line contents.private boolean
Whether a line ending with a CR is pending processing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 tohandleLine(java.lang.String, java.lang.String)
.private boolean
finishLine
(boolean sawNewline) Called when a line is complete.protected abstract void
handleLine
(String line, String end) Called for each line found in the character data passed toadd(char[], int, int)
.
-
Field Details
-
line
Holds partial line contents. -
sawReturn
private boolean sawReturnWhether a line ending with a CR is pending processing.
-
-
Constructor Details
-
LineBuffer
LineBuffer()
-
-
Method Details
-
add
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 abstracthandleLine(java.lang.String, java.lang.String)
method.- Parameters:
cbuf
- the character buffer to processoff
- the offset into the bufferlen
- the number of characters to process- Throws:
IOException
- if an I/O error occurs- See Also:
-
finishLine
Called when a line is complete.- Throws:
IOException
-
finish
Subclasses must call this method after finishing character processing, in order to ensure that any unterminated line in the buffer is passed tohandleLine(java.lang.String, java.lang.String)
.- Throws:
IOException
- if an I/O error occurs
-
handleLine
Called for each line found in the character data passed toadd(char[], int, int)
.- Parameters:
line
- a line of text (possibly empty), without any line separatorsend
- the line separator; one of"\r"
,"\n"
,"\r\n"
, or""
- Throws:
IOException
- if an I/O error occurs
-