Top Description Fields Constructors Methods
com.google.common.io

pack-priv abstract Class LineBuffer

extends Object
Class Inheritance
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtIncompatible, .J2ktIncompatible, com.google.errorprone.annotations.CanIgnoreReturnValue, java.io.IOException

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

Subclasses must implement handleLine, call add to pass character data, and call finish at the end of stream.

Author
Chris Nokleberg
Since
1.0

Field Summary

Modifier and TypeField and Description
private StringBuilder
line

Holds partial line contents.

private boolean
sawReturn

Whether a line ending with a CR is pending processing.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
add(char[]
the character buffer to process
cbuf
,
int
the offset into the buffer
off
,
int
the number of characters to process
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.

private boolean
finishLine(boolean sawNewline)

Called when a line is complete.

protected abstract void
handleLine(String
a line of text (possibly empty), without any line separators
line
,
String
the line separator; one of "\r", "\n", "\r\n", or ""
end
)

Called for each line found in the character data passed to add.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lineback to summary
private StringBuilder line

Holds partial line contents.

sawReturnback to summary
private boolean sawReturn

Whether a line ending with a CR is pending processing.

Constructor Detail

LineBufferback to summary
pack-priv LineBuffer()

Method Detail

addback to summary
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 method.

Parameters
cbuf:char[]

the character buffer to process

off:int

the offset into the buffer

len:int

the number of characters to process

Exceptions
IOException:
if an I/O error occurs
See Also
finish
finishback to summary
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.

Exceptions
IOException:
if an I/O error occurs
finishLineback to summary
private boolean finishLine(boolean sawNewline) throws IOException

Called when a line is complete.

Annotations
@CanIgnoreReturnValue
handleLineback to summary
protected abstract void handleLine(String line, String end) throws IOException

Called for each line found in the character data passed to add.

Parameters
line:String

a line of text (possibly empty), without any line separators

end:String

the line separator; one of "\r", "\n", "\r\n", or ""

Exceptions
IOException:
if an I/O error occurs