com.twitter.common.io
Interface Streamer<T>


public interface Streamer<T>

Encapsulates iteration over a typed data stream that can be filtered.


Method Summary
 Streamer<T> endOn(Predicate<T> cond)
          Returns a Streamer that will process the same stream as this streamer, but will stop processing when encountering the first item for which cond is true.
 Streamer<T> filter(Predicate<T> filter)
          Returns a Streamer that will process the same stream as this streamer, but with any items failing the filter to be omitted from processing.
 void process(Closure<T> work)
          Processes a stream fully.
 

Method Detail

process

void process(Closure<T> work)
Processes a stream fully. This may cause a database query to be executed, a file to be read or even just call Iterable.iterator() depending on the implementation. Implementations guaranty that any resources allocated opening the stream will be closed whether or not process completes normally.

Parameters:
work - a closure over the work to be done for each item in the stream.

endOn

Streamer<T> endOn(Predicate<T> cond)
Returns a Streamer that will process the same stream as this streamer, but will stop processing when encountering the first item for which cond is true.

Parameters:
cond - a predicate that returns false as long as the stream should keep being processed.
Returns:
a streamer that will process items until the condition triggers.

filter

Streamer<T> filter(Predicate<T> filter)
Returns a Streamer that will process the same stream as this streamer, but with any items failing the filter to be omitted from processing.

Parameters:
filter - a predicate that returns true if an item in the stream should be processed
Returns:
a filtered streamer