public abstract class AbstractPipe extends java.lang.Object implements Feeder, Drainer
a skeleton implementation of a combination of Feeder
and Drainer
. Subclasses only need
to implement pipe()
.
This class implements the run()
method required by
the Feeder
and Drainer
interfaces. It
calls pipe()
, catches any exceptions thrown and closes
the provided streams as requested by the 2nd
parameters of setOut()
and setIn()
.
Objects of this class may be reused within a single
thread as long as setIn()
and/or setOut()
are called as necessary before each invocation of the
run()
method.
A subclass need not make use of both, input and output. If it
generates data, it can choose to only use the output stream
provided by setOut()
, thereby actually being a
Feeder
only. A pure data sink, i.e. a Drainer
,
results if only the provided input stream is used.
Of course such subclasses should then only be used as either
Feeder
or Drainer
such that the unused
stream is never set anyway.
Constructor and Description |
---|
AbstractPipe() |
Modifier and Type | Method and Description |
---|---|
java.lang.Exception |
getException()
objects implementing this interface should return any exception
worth reporting that happened during
run() . |
void |
run()
calls
pipe() , handles exceptions and closes input and
output streams where necessary and requested. |
void |
setIn(java.io.InputStream in,
boolean closeOnExit)
specifies the
InputStream where to fetch the
data in the run() method. |
void |
setOut(java.io.OutputStream out,
boolean closeOnExit)
specifies the
OutputStream where to deliver the
data in the run() method. |
public java.lang.Exception getException()
Service
objects implementing this interface should return any exception
worth reporting that happened during run()
.
getException
in interface Service
public void setOut(java.io.OutputStream out, boolean closeOnExit)
Feeder
specifies the OutputStream
where to deliver the
data in the run()
method.
public void setIn(java.io.InputStream in, boolean closeOnExit)
Drainer
specifies the InputStream
where to fetch the
data in the run()
method.
public void run()
calls pipe()
, handles exceptions and closes input and
output streams where necessary and requested.
This method ignores the exceptions InterruptedIOException
and InterruptedException
when thrown or passed on by
pipe()
as valid requests to stop operations
prematurely.
run
in interface java.lang.Runnable