Package org.apache.tika.io
Class TaggedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.tika.io.ProxyInputStream
-
- org.apache.tika.io.TaggedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
TikaInputStream
public class TaggedInputStream extends ProxyInputStream
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 theTaggedIOExceptionclass to wrap all thrownIOExceptions. 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 }- See Also:
TaggedIOException
-
-
Constructor Summary
Constructors Constructor Description TaggedInputStream(java.io.InputStream proxy)Creates a tagging decorator for the given input stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TaggedInputStreamget(java.io.InputStream proxy)Casts or wraps the given stream to a TaggedInputStream instance.booleanisCauseOf(java.io.IOException exception)Tests if the given exception was caused by this stream.voidthrowIfCauseOf(java.lang.Exception exception)Re-throws the original exception thrown by this stream.java.lang.StringtoString()-
Methods inherited from class org.apache.tika.io.ProxyInputStream
available, close, mark, markSupported, read, read, read, reset, skip
-
-
-
-
Method Detail
-
get
public static TaggedInputStream get(java.io.InputStream proxy)
Casts or wraps the given stream to a TaggedInputStream instance.- Parameters:
proxy- normal input stream- Returns:
- a TaggedInputStream instance
-
isCauseOf
public boolean isCauseOf(java.io.IOException exception)
Tests if the given exception was caused by this stream.- Parameters:
exception- an exception- Returns:
trueif the exception was thrown by this stream,falseotherwise
-
throwIfCauseOf
public void throwIfCauseOf(java.lang.Exception exception) throws java.io.IOExceptionRe-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:
java.io.IOException- original exception, if any, thrown by this stream
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-