Package org.apache.commons.io.input
Class TaggedReader
java.lang.Object
java.io.Reader
java.io.FilterReader
org.apache.commons.io.input.ProxyReader
org.apache.commons.io.input.TaggedReader
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Readable
A reader decorator that tags potential exceptions so that the reader 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.
 
 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
 }
 
 Deprecating Serialization
Serialization is deprecated and will be removed in 3.0.
- Since:
- 2.7
- See Also:
- 
Field SummaryFields inherited from class java.io.FilterReaderin
- 
Constructor SummaryConstructorsConstructorDescriptionTaggedReader(Reader proxy) Constructs a tagging decorator for the given reader.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidTags any IOExceptions thrown, wrapping and re-throwing.booleanTests if the given exception was caused by this reader.voidthrowIfCauseOf(Throwable throwable) Re-throws the original exception thrown by this reader.Methods inherited from class org.apache.commons.io.input.ProxyReaderafterRead, beforeRead, close, mark, markSupported, read, read, read, read, ready, reset, skip
- 
Constructor Details- 
TaggedReaderConstructs a tagging decorator for the given reader.- Parameters:
- proxy- reader to be decorated
 
 
- 
- 
Method Details- 
handleIOExceptionTags any IOExceptions thrown, wrapping and re-throwing.- Overrides:
- handleIOExceptionin class- ProxyReader
- Parameters:
- e- The IOException thrown
- Throws:
- IOException- if an I/O error occurs.
 
- 
isCauseOfTests if the given exception was caused by this reader.- Parameters:
- exception- an exception
- Returns:
- trueif the exception was thrown by this reader,- falseotherwise
 
- 
throwIfCauseOfRe-throws the original exception thrown by this reader. This method first checks whether the given exception is aTaggedIOExceptionwrapper created by this decorator, and then unwraps and throws the original wrapped exception. Returns normally if the exception was not thrown by this reader.- Parameters:
- throwable- an exception
- Throws:
- IOException- original exception, if any, thrown by this reader
 
 
-