public class TaggedInputStream extends ProxyInputStream
TaggedIOException class to wrap all thrown
IOExceptions. See below for an example of using this class.
TaggedInputStream stream = new TaggedInputStream(...);
try {
// Processing that may throw an IOException either from this stream
// or from some other IO activity like temporary files, etc.
processStream(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(Throwable) 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.
TaggedInputStream stream = new TaggedInputStream(...);
try {
processStream(stream);
} catch (IOException e) {
stream.throwIfCauseOf(e);
// ... or process the exception that was caused by something else
}
TaggedIOException| Modifier and Type | Field and Description |
|---|---|
private java.io.Serializable |
tag
The unique tag associated with exceptions from stream.
|
| Constructor and Description |
|---|
TaggedInputStream(java.io.InputStream proxy)
Creates a tagging decorator for the given input stream.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
handleIOException(java.io.IOException e)
Tags any IOExceptions thrown, wrapping and re-throwing.
|
boolean |
isCauseOf(java.lang.Throwable exception)
Tests if the given exception was caused by this stream.
|
void |
throwIfCauseOf(java.lang.Throwable throwable)
Re-throws the original exception thrown by this stream.
|
afterRead, available, beforeRead, close, mark, markSupported, read, read, read, reset, skipprivate final java.io.Serializable tag
public TaggedInputStream(java.io.InputStream proxy)
proxy - input stream to be decoratedpublic boolean isCauseOf(java.lang.Throwable exception)
exception - an exceptiontrue if the exception was thrown by this stream,
false otherwisepublic void throwIfCauseOf(java.lang.Throwable throwable)
throws java.io.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.throwable - an exceptionjava.io.IOException - original exception, if any, thrown by this streamprotected void handleIOException(java.io.IOException e)
throws java.io.IOException
handleIOException in class ProxyInputStreame - The IOException thrownjava.io.IOException - if an I/O error occursCopyright (c) 2002-2016 Apache Software Foundation