Class LineCollector

java.lang.Object
org.jgrapes.io.util.LineCollector

public class LineCollector extends Object
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 Details

  • Method Details

    • charset

      public LineCollector charset(Charset charset)
      Sets the charset to be used if feed(ManagedBuffer) is invoked with ManagedBuffer<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 if feed(ManagedBuffer) is invoked with ManagedBuffer<ByteBuffer> to the charset specified as system property native.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

      public LineCollector consumer(Consumer<String> 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 returns null).

      Parameters:
      consumer - the consumer
      Returns:
      the line collector
    • feed

      public <W extends Buffer> void feed(W buffer)
      Feed data to the collector.

      Calling this method with null as argument closes the feed.

      Parameters:
      buffer - the buffer
    • feed

      public <W extends Buffer> void feed(ManagedBuffer<W> buffer)
      Feed data to the collector.

      Calling this method with null as argument closes the feed.

      Parameters:
      buffer - the buffer
    • feed

      public <W extends Buffer> void feed(Input<W> event)
      Feed data to the collector.

      Calling this method with null as argument closes the feed.

      Parameters:
      event - the event
    • eof

      public boolean eof()
      Checks if more input may become available.
      Returns:
      true, if successful
    • getLine

      public String getLine()
      Gets the next line.
      Returns:
      the line