Package com.google.common.io
Class LineBuffer
- java.lang.Object
-
- com.google.common.io.LineBuffer
-
abstract class LineBuffer extends java.lang.Object
Package-protected abstract class that implements the line reading algorithm used byLineReader
. Line separators are perBufferedReader
: line feed, carriage return, or carriage return followed immediately by a linefeed.Subclasses must implement
handleLine(java.lang.String, java.lang.String)
, calladd(char[], int, int)
to pass character data, and callfinish()
at the end of stream.- Since:
- 1.0
-
-
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 tohandleLine(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 toadd(char[], int, int)
.
-
-
-
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 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:
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 tohandleLine(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 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:
java.io.IOException
- if an I/O error occurs
-
-