Skip to content

Commit f89a19f

Browse files
committed
TIKA-1935
1 parent d692390 commit f89a19f

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

tika-parsers/src/main/java/org/apache/tika/parser/isatab/ISArchiveParser.java

+32-22
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Set;
2525

2626
import org.apache.tika.exception.TikaException;
27+
import org.apache.tika.io.TemporaryResources;
2728
import org.apache.tika.io.TikaInputStream;
2829
import org.apache.tika.metadata.Metadata;
2930
import org.apache.tika.mime.MediaType;
@@ -75,29 +76,38 @@ public Set<MediaType> getSupportedTypes(ParseContext context) {
7576
public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
7677
ParseContext context) throws IOException, SAXException, TikaException {
7778

78-
TikaInputStream tis = TikaInputStream.get(stream);
79-
if (this.location == null) {
80-
this.location = tis.getFile().getParent() + File.separator;
81-
}
82-
this.studyFileName = tis.getFile().getName();
83-
84-
File locationFile = new File(location);
85-
String[] investigationList = locationFile.list(new FilenameFilter() {
86-
87-
@Override
88-
public boolean accept(File dir, String name) {
89-
return name.matches("i_.+\\.txt");
79+
TemporaryResources tmp = TikaInputStream.isTikaInputStream(stream) ? null :
80+
new TemporaryResources();
81+
82+
TikaInputStream tis = TikaInputStream.get(stream, tmp);
83+
try {
84+
if (this.location == null) {
85+
this.location = tis.getFile().getParent() + File.separator;
9086
}
91-
});
92-
93-
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
94-
xhtml.startDocument();
95-
96-
parseInvestigation(investigationList, xhtml, metadata, context);
97-
parseStudy(stream, xhtml, metadata, context);
98-
parseAssay(xhtml, metadata, context);
99-
100-
xhtml.endDocument();
87+
this.studyFileName = tis.getFile().getName();
88+
89+
File locationFile = new File(location);
90+
String[] investigationList = locationFile.list(new FilenameFilter() {
91+
92+
@Override
93+
public boolean accept(File dir, String name) {
94+
return name.matches("i_.+\\.txt");
95+
}
96+
});
97+
98+
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
99+
xhtml.startDocument();
100+
101+
parseInvestigation(investigationList, xhtml, metadata, context);
102+
parseStudy(stream, xhtml, metadata, context);
103+
parseAssay(xhtml, metadata, context);
104+
105+
xhtml.endDocument();
106+
} finally {
107+
if (tmp != null) {
108+
tmp.dispose();
109+
}
110+
}
101111
}
102112

103113
private void parseInvestigation(String[] investigationList, XHTMLContentHandler xhtml, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {

0 commit comments

Comments
 (0)