An input stream decorator that tags potential exceptions so that the
stream that caused the exception can easily be identified. This is
done by using the
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(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.
TaggedInputStream stream = new TaggedInputStream(...);
try {
processStream(stream);
} catch (IOException e) {
stream.throwIfCauseOf(e);
// ... or process the exception that was caused by something else
}