You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/10/19 06:26:05 UTC
[camel] 01/03: Camel-Tika: Better handling of InputStream in
producer
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 413347791ceea5a0b59d8692a4a85eb19fb76de4
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Oct 19 08:18:54 2020 +0200
Camel-Tika: Better handling of InputStream in producer
---
.../java/org/apache/camel/component/tika/TikaProducer.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
index 222fba8..62e8256 100644
--- a/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
+++ b/components/camel-tika/src/main/java/org/apache/camel/component/tika/TikaProducer.java
@@ -96,25 +96,27 @@ public class TikaProducer extends DefaultProducer {
}
private Object doDetect(Exchange exchange) throws IOException {
- InputStream inputStream = exchange.getIn().getBody(InputStream.class);
+ MediaType result;
+ try (InputStream inputStream = exchange.getIn().getBody(InputStream.class)) {
Metadata metadata = new Metadata();
- MediaType result = this.detector.detect(inputStream, metadata);
+ result = this.detector.detect(inputStream, metadata);
convertMetadataToHeaders(metadata, exchange);
- inputStream.close();
+ }
return result.toString();
}
private Object doParse(Exchange exchange)
throws TikaException, IOException, SAXException, TransformerConfigurationException {
- InputStream inputStream = exchange.getIn().getBody(InputStream.class);
+
OutputStream result = new ByteArrayOutputStream();
+ try (InputStream inputStream = exchange.getIn().getBody(InputStream.class)) {
ContentHandler contentHandler = getContentHandler(this.tikaConfiguration, result);
ParseContext context = new ParseContext();
context.set(Parser.class, this.parser);
Metadata metadata = new Metadata();
this.parser.parse(inputStream, contentHandler, metadata, context);
convertMetadataToHeaders(metadata, exchange);
- inputStream.close();
+ }
return result;
}