Package org.jgrapes.io.util
Class LineCollector
java.lang.Object
org.jgrapes.io.util.LineCollector
- All Implemented Interfaces:
InputConsumer
Collects character data from buffers and makes it available as
complete lines.
Lines end with a LF which may optionally be followed by a CR.
Neither character is part of the result returned by getLine()
.
If no more input is expected and characters without trailing LF
remain, these remaining character are returned as a line as well.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionSets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
.Configures a consumer for lines.boolean
eof()
Checks if more input may become available.<W extends Buffer>
voidfeed
(ManagedBuffer<W> buffer) Feed data to the collector.<W extends Buffer>
voidfeed
(W buffer) Feed data to the collector.getLine()
Gets the next line.Sets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
to the charset specified as system propertynative.encoding
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jgrapes.io.util.InputConsumer
feed
-
Constructor Details
-
LineCollector
public LineCollector()
-
-
Method Details
-
charset
Sets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
.Defaults to UTF-8. Must be set before the first invocation of
feed(ManagedBuffer)
.- Parameters:
charset
- the charset- Returns:
- the managed buffer reader
-
nativeCharset
Sets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
to the charset specified as system propertynative.encoding
.If this property does not specify a valid charset,
Charset.defaultCharset()
is used.Must be invoked before the first invocation of
feed(ManagedBuffer)
.- Returns:
- the managed buffer reader
-
consumer
Configures a consumer for lines.The consumer is invoked when a complete line has been detected. If a consumer is configured,
getLine()
may not be used (always returnsnull
).- Parameters:
consumer
- the consumer- Returns:
- the line collector
-
feed
Feed data to the collector.Calling this method with
null
as argument closes the feed.- Parameters:
buffer
- the buffer
-
feed
Feed data to the collector.Calling this method with
null
as argument closes the feed.- Specified by:
feed
in interfaceInputConsumer
- Parameters:
buffer
- the buffer
-
eof
Checks if more input may become available.- Returns:
- true, if successful
-
getLine
Gets the next line.- Returns:
- the line
-