T - the type of convertible objectpublic final class Pipe<T> extends Object
This class helps to chains transformers that read InputStream and writes some transformed bytes to a
ByteArrayOutputStream.
| Modifier and Type | Class and Description |
|---|---|
static class |
Pipe.DefaultOnReady
Default implementation which writes the result to a wrapped output stream and close if automatically.
|
static class |
Pipe.DefaultTransformer<T>
The default transformer just copies the
InputStream to the OutputStream and produces a content
which can be aggregated to an other one. |
static class |
Pipe.Execution
This class represents the result of the transformation made by thanks to piped transformers.
|
static interface |
Pipe.OnReady
This class represents an object notified when a transformation is done.
|
static interface |
Pipe.Transformer<T>
This interface describes an object which is able to write into an
OutputStream some transformed bytes
read from InputStream. |
| Constructor and Description |
|---|
Pipe(T c,
InputStream is)
Creates a new instance with an input.
|
| Modifier and Type | Method and Description |
|---|---|
void |
execute(Pipe.OnReady... onReady)
Executes this pipe by writing a byte array the result generated by all
registered
transformers. |
static <T> void |
executeAndWriteTo(Pipe<T> pipe,
List<Pipe.OnReady> callbacks,
OutputStream os)
Executes the given pipe and writes the result into the given
OutputStream. |
void |
register(Pipe.Transformer<T> transformer)
Registers the given
Pipe.Transformer to the pipe. |
public Pipe(T c, InputStream is)
Creates a new instance with an input.
c - the convertible bound to the input streamis - the InputStreampublic static <T> void executeAndWriteTo(Pipe<T> pipe, List<Pipe.OnReady> callbacks, OutputStream os) throws IOException
Executes the given pipe and writes the result into the given OutputStream.
T - the type of object converted by the piped transformerspipe - the pipe to executeos - the stream to writeIOException - if transformation failspublic void register(Pipe.Transformer<T> transformer) throws IOException
Registers the given Pipe.Transformer to the pipe. The InputStream sent to this transformer with be
connected to the OutputStream of the Pipe.Transformer previously registered.
transformer - the transformerIOException - if streams could not be pipedpublic void execute(Pipe.OnReady... onReady) throws IOException
Executes this pipe by writing a byte array the result generated by all
registered transformers.
Once transformation has been done, callback is notified.
onReady - callbackIOException - if an I/O error occursCopyright © 2012-2015. All Rights Reserved.