|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.FilterInputStream org.apache.tika.io.ProxyInputStream org.apache.tika.io.TaggedInputStream
public class TaggedInputStream
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
IOException
s. 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 }
TaggedIOException
Field Summary |
---|
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
TaggedInputStream(InputStream proxy)
Creates a tagging decorator for the given input stream. |
Method Summary | |
---|---|
static TaggedInputStream |
get(InputStream proxy)
Casts or wraps the given stream to a TaggedInputStream instance. |
protected void |
handleIOException(IOException e)
Tags any IOExceptions thrown, wrapping and re-throwing. |
boolean |
isCauseOf(IOException exception)
Tests if the given exception was caused by this stream. |
void |
throwIfCauseOf(Exception exception)
Re-throws the original exception thrown by this stream. |
String |
toString()
|
Methods inherited from class org.apache.tika.io.ProxyInputStream |
---|
afterRead, available, beforeRead, close, mark, markSupported, read, read, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TaggedInputStream(InputStream proxy)
proxy
- input stream to be decoratedMethod Detail |
---|
public static TaggedInputStream get(InputStream proxy)
stream
- normal input stream
public boolean isCauseOf(IOException exception)
exception
- an exception
true
if the exception was thrown by this stream,
false
otherwisepublic void throwIfCauseOf(Exception exception) 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 stream.
exception
- an exception
IOException
- original exception, if any, thrown by this streamprotected void handleIOException(IOException e) throws IOException
handleIOException
in class ProxyInputStream
e
- The IOException thrown
IOException
- if an I/O error occurspublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |