public class ExceptionPassingPipedOutputStream extends PipedOutputStream
PipedInputStream
/ PipedOutputStream
pair allows to pass on exceptions from the input to the output end.ExceptionPassingPipedInputStream
Modifier and Type | Class and Description |
---|---|
static interface |
ExceptionPassingPipedOutputStream.ICloseExceptionHandler
An exception handler for exceptions that have been passed in from the
fellow
ExceptionPassingPipedInputStream but not handled when
someone tries to close this stream. |
static class |
ExceptionPassingPipedOutputStream.OtherSideException
If you pass in an exception that is neither an IOException nor a
RuntimeException, it is encapsulated to this.
|
Constructor and Description |
---|
ExceptionPassingPipedOutputStream() |
ExceptionPassingPipedOutputStream(ExceptionPassingPipedInputStream snk) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
connect(PipedInputStream snk) |
void |
done() |
void |
flush() |
Throwable |
getException()
The last, yet unthrown exception passed in by
ExceptionPassingPipedInputStream.passOnException(Throwable) |
boolean |
isBlockingClose()
if true, do not return from
close() until someone has called the
done() method on the connected ExceptionPassingPipedOutputStream . |
void |
setBlockingClose(boolean blockingClose)
if true, do not return from
close() until someone has called the
done() method on the connected ExceptionPassingPipedOutputStream |
void |
setCloseExceptionHandler(ExceptionPassingPipedOutputStream.ICloseExceptionHandler handler)
Sets an exception handler for exceptions not yet thrown when the stream's
close() method is called. |
protected void |
tryThrowException()
Helper method that throws an exception if the other side has called
ExceptionPassingPipedInputStream.passOnException(Throwable) . |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
write
public ExceptionPassingPipedOutputStream()
public ExceptionPassingPipedOutputStream(ExceptionPassingPipedInputStream snk) throws IOException
IOException
public void setCloseExceptionHandler(ExceptionPassingPipedOutputStream.ICloseExceptionHandler handler)
close()
method is called.
Close will first wait for the partner to call done()
if it
isBlockingClose()
, then check whether an unhandled exception is
still remaining and a handler has been set and if so, call the handler's
handleException method. If the latter returns false
, the
exception will be thrown (potentially wrapped in an
ExceptionPassingPipedOutputStream.OtherSideException
).handler
- the handlerpublic void setBlockingClose(boolean blockingClose)
close()
until someone has called the
done() method on the connected ExceptionPassingPipedOutputStream
public boolean isBlockingClose()
close()
until someone has called the
done() method on the connected ExceptionPassingPipedOutputStream
.
The default is false
, call
setBlockingClose(boolean)
to force block behaviour.public Throwable getException()
ExceptionPassingPipedInputStream.passOnException(Throwable)
null
.protected void tryThrowException() throws IOException
ExceptionPassingPipedInputStream.passOnException(Throwable)
.
Every exception passed in this way is thrown only once (i.e. the field is
cleared).IOException
- if the other side has passed us a IOException
RuntimeException
- if the other side has passed us a RuntimeException
ExceptionPassingPipedOutputStream.OtherSideException
- (which is an IOException
) if the other side has
passed in something else, which you will find in the
exception's cause fieldpublic void flush() throws IOException
flush
in interface Flushable
flush
in class PipedOutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class PipedOutputStream
IOException
public void write(int b) throws IOException
write
in class PipedOutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class PipedOutputStream
IOException
public void connect(PipedInputStream snk) throws IOException
connect
in class PipedOutputStream
IOException
public void done()