public class TaggedReader extends ProxyReader
TaggedIOException
class to wrap all thrown IOException
s. See
below for an example of using this class.
TaggedReader reader = new TaggedReader(...); try { // Processing that may throw an IOException either from this reader // or from some other IO activity like temporary files, etc. processReader(reader); } catch (IOException e) { if (reader.isCauseOf(e)) { // The exception was caused by this reader. // 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 reader while other processing errors are being taken care of at this lower level.
TaggedReader reader = new TaggedReader(...); try { processReader(reader); } catch (IOException e) { reader.throwIfCauseOf(e); // ... or process the exception that was caused by something else }
TaggedIOException
in
Constructor and Description |
---|
TaggedReader(Reader proxy)
Creates a tagging decorator for the given reader.
|
Modifier and Type | Method and Description |
---|---|
protected void |
handleIOException(IOException e)
Tags any IOExceptions thrown, wrapping and re-throwing.
|
boolean |
isCauseOf(Throwable exception)
Tests if the given exception was caused by this reader.
|
void |
throwIfCauseOf(Throwable throwable)
Re-throws the original exception thrown by this reader.
|
afterRead, beforeRead, close, mark, markSupported, read, read, read, read, ready, reset, skip
public TaggedReader(Reader proxy)
proxy
- reader to be decoratedpublic boolean isCauseOf(Throwable exception)
exception
- an exceptiontrue
if the exception was thrown by this reader, false
otherwisepublic void throwIfCauseOf(Throwable throwable) 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 reader.throwable
- an exceptionIOException
- original exception, if any, thrown by this readerprotected void handleIOException(IOException e) throws IOException
handleIOException
in class ProxyReader
e
- The IOException thrownIOException
- if an I/O error occursCopyright © 2002–2020 The Apache Software Foundation. All rights reserved.