Package org.apache.commons.io.output
Class TaggedOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.apache.commons.io.output.ProxyOutputStream
org.apache.commons.io.output.TaggedOutputStream
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable
An output 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.
 
 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
 }
 - Since:
- 2.0
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.commons.io.output.ProxyOutputStreamProxyOutputStream.Builder
- 
Field SummaryFields inherited from class java.io.FilterOutputStreamout
- 
Constructor SummaryConstructorsConstructorDescriptionTaggedOutputStream(OutputStream proxy) Constructs a tagging decorator for the given output stream.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidTags any IOExceptions thrown, wrapping and re-throwing.booleanTests if the given exception was caused by this stream.voidthrowIfCauseOf(Exception exception) Re-throws the original exception thrown by this stream.Methods inherited from class org.apache.commons.io.output.ProxyOutputStreamafterWrite, beforeWrite, close, flush, setReference, write, write, write
- 
Constructor Details- 
TaggedOutputStreamConstructs a tagging decorator for the given output stream.- Parameters:
- proxy- output stream to be decorated
 
 
- 
- 
Method Details- 
handleIOExceptionTags any IOExceptions thrown, wrapping and re-throwing.- Overrides:
- handleIOExceptionin class- ProxyOutputStream
- Parameters:
- e- The IOException thrown
- Throws:
- IOException- if an I/O error occurs.
 
- 
isCauseOfTests if the given exception was caused by this stream.- Parameters:
- exception- an exception
- Returns:
- trueif the exception was thrown by this stream,- falseotherwise
 
- 
throwIfCauseOfRe-throws the original exception thrown by this stream. 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 stream.- Parameters:
- exception- an exception
- Throws:
- IOException- original exception, if any, thrown by this stream
 
 
-