You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2016/04/06 14:23:04 UTC
tika git commit: TIKA-1932
Repository: tika
Updated Branches:
refs/heads/master e9206475e -> 27f1b8f72
TIKA-1932
Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/27f1b8f7
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/27f1b8f7
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/27f1b8f7
Branch: refs/heads/master
Commit: 27f1b8f726d7757c4aa57a0e3ae07d3e22cdfba7
Parents: e920647
Author: tballison <ta...@mitre.org>
Authored: Wed Apr 6 08:22:43 2016 -0400
Committer: tballison <ta...@mitre.org>
Committed: Wed Apr 6 08:22:43 2016 -0400
----------------------------------------------------------------------
.../org/apache/tika/parser/ParserDecorator.java | 28 +++++++++++---------
1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tika/blob/27f1b8f7/tika-core/src/main/java/org/apache/tika/parser/ParserDecorator.java
----------------------------------------------------------------------
diff --git a/tika-core/src/main/java/org/apache/tika/parser/ParserDecorator.java b/tika-core/src/main/java/org/apache/tika/parser/ParserDecorator.java
index f1865f3..213edd1 100644
--- a/tika-core/src/main/java/org/apache/tika/parser/ParserDecorator.java
+++ b/tika-core/src/main/java/org/apache/tika/parser/ParserDecorator.java
@@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.tika.exception.TikaException;
+import org.apache.tika.io.CloseShieldInputStream;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
@@ -120,19 +121,22 @@ public class ParserDecorator extends AbstractParser {
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
// Must have a TikaInputStream, so we can re-use it if parsing fails
- TikaInputStream tstream = TikaInputStream.get(stream);
- tstream.getFile();
- // Try each parser in turn
- for (Parser p : parsers) {
- tstream.mark(-1);
- try {
- p.parse(tstream, handler, metadata, context);
- return;
- } catch (Exception e) {
- // TODO How to log / record this failure?
+ // Need to close internally created tstream to release resources
+ try (TikaInputStream tstream =
+ TikaInputStream.get(new CloseShieldInputStream(stream))) {
+ tstream.getFile();
+ // Try each parser in turn
+ for (Parser p : parsers) {
+ tstream.mark(-1);
+ try {
+ p.parse(tstream, handler, metadata, context);
+ return;
+ } catch (Exception e) {
+ // TODO How to log / record this failure?
+ }
+ // Prepare for the next parser, if present
+ tstream.reset();
}
- // Prepare for the next parser, if present
- tstream.reset();
}
}
@Override