com.twitter.common.io
Class SerializedFileStreamer<T extends Serializable>

java.lang.Object
  extended by com.twitter.common.io.SerializedFileStreamer<T>
All Implemented Interfaces:
Streamer<T>

public class SerializedFileStreamer<T extends Serializable>
extends Object
implements Streamer<T>

A streamer that reads from serialized files.


Constructor Summary
SerializedFileStreamer(Iterable<? extends ObjectInputStream> inputs)
          Returns a streamer that will deserialize objects of type T from a set of files in the order the files are given.
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializedFileStreamer

public SerializedFileStreamer(Iterable<? extends ObjectInputStream> inputs)
Returns a streamer that will deserialize objects of type T from a set of files in the order the files are given.

Parameters:
inputs - The input streams to read from.
Method Detail

endOn

public Streamer<T> endOn(Predicate<T> cond)
Description copied from interface: Streamer
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.

Specified by:
endOn in interface Streamer<T extends Serializable>
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.

process

public void process(Closure<T> work)
Description copied from interface: Streamer
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.

Specified by:
process in interface Streamer<T extends Serializable>
Parameters:
work - a closure over the work to be done for each item in the stream.

filter

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

Specified by:
filter in interface Streamer<T extends Serializable>
Parameters:
filter - a predicate that returns true if an item in the stream should be processed
Returns:
a filtered streamer