|
24 | 24 | import java.util.Set;
|
25 | 25 |
|
26 | 26 | import org.apache.tika.exception.TikaException;
|
| 27 | +import org.apache.tika.io.TemporaryResources; |
27 | 28 | import org.apache.tika.io.TikaInputStream;
|
28 | 29 | import org.apache.tika.metadata.Metadata;
|
29 | 30 | import org.apache.tika.mime.MediaType;
|
@@ -75,29 +76,38 @@ public Set<MediaType> getSupportedTypes(ParseContext context) {
|
75 | 76 | public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
|
76 | 77 | ParseContext context) throws IOException, SAXException, TikaException {
|
77 | 78 |
|
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; |
90 | 86 | }
|
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 | + } |
101 | 111 | }
|
102 | 112 |
|
103 | 113 | private void parseInvestigation(String[] investigationList, XHTMLContentHandler xhtml, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
|
|
0 commit comments