public class TaggedOutputStream extends ProxyOutputStream
TaggedIOException class to wrap all thrown
IOExceptions. See below for an example of using this class.
TaggedOutputStream stream = new TaggedOutputStream(...);
try {
// Processing that may throw an IOException either from this stream
// or from some other IO activity like temporary files, etc.
writeToStream(stream);
} catch (IOException e) {
if (stream.isCauseOf(e)) {
// The exception was caused by this stream.
// Use e.getCause() to get the original exception.
} else {
// The exception was caused by something else.
}
}
Alternatively, the throwIfCauseOf(Exception) method can be
used to let higher levels of code handle the exception caused by this
stream while other processing errors are being taken care of at this
lower level.
TaggedOutputStream stream = new TaggedOutputStream(...);
try {
writeToStream(stream);
} catch (IOException e) {
stream.throwIfCauseOf(e);
// ... or process the exception that was caused by something else
}
TaggedIOExceptionout| 构造器和说明 |
|---|
TaggedOutputStream(OutputStream proxy)
Creates a tagging decorator for the given output stream.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
handleIOException(IOException e)
Tags any IOExceptions thrown, wrapping and re-throwing.
|
boolean |
isCauseOf(Exception exception)
Tests if the given exception was caused by this stream.
|
void |
throwIfCauseOf(Exception exception)
Re-throws the original exception thrown by this stream.
|
afterWrite, beforeWrite, close, flush, write, write, writepublic TaggedOutputStream(OutputStream proxy)
proxy - output stream to be decoratedpublic boolean isCauseOf(Exception exception)
exception - an exceptiontrue if the exception was thrown by this stream,
false otherwisepublic void throwIfCauseOf(Exception exception) throws IOException
TaggedIOException
wrapper created by this decorator, and then unwraps and throws the
original wrapped exception. Returns normally if the exception was
not thrown by this stream.exception - an exceptionIOException - original exception, if any, thrown by this streamprotected void handleIOException(IOException e) throws IOException
handleIOException 在类中 ProxyOutputStreame - The IOException thrownIOException - if an I/O error occurs