[
https://issues.apache.org/jira/browse/CAMEL-13373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16803050#comment-16803050
]
Alexandru commented on CAMEL-13373:
-----------------------------------
Each time we have a from("file://).to(stax://) after camel finishes to process
the route we observe a FileInputStream not closed.
After analyzing who was responsible for opening the FileInputStream, i found
that the StAXProcessor.java was in cause.
t I opens the stream for reading (line; reader.parse(is) but it never closes it.
So, i had to modify the source code by adding a try with resources at the line
in bold.
Is it more clear ? or should i open a PR and post the link here ?
Thanks
> FileInputStream not closed
> --------------------------
>
> Key: CAMEL-13373
> URL: https://issues.apache.org/jira/browse/CAMEL-13373
> Project: Camel
> Issue Type: Bug
> Components: camel-stax
> Affects Versions: 2.23.1
> Reporter: Alexandru
> Priority: Major
>
> The StAXProcessor.java class does not close the stream it opens.
> I had to modify it like this:
> public void process(Exchange exchange) throws Exception {
> InputSource is = exchange.getIn().getMandatoryBody(InputSource.class);
> XMLStreamReader stream =
> exchange.getIn().getMandatoryBody(XMLStreamReader.class);
> // Fermeture de la inputstream ici, car dans la version originale de la
> classe la stream reste ouverte.
> *try(InputStream inputStreamToClose = is.getByteStream()) {*
> XMLReader reader = new StaxStreamXMLReader(stream);
> ContentHandler handler;
> if (this.contentHandlerClass != null)
> { handler = (ContentHandler) this.contentHandlerClass.newInstance(); }
> else
> { handler = this.contentHandler; }
> reader.setContentHandler(handler);
> reader.parse(is);
> if (ExchangeHelper.isOutCapable(exchange))
> { exchange.getOut().setHeaders(exchange.getIn().getHeaders());
> exchange.getOut().setBody(handler); }
> else
> { exchange.getIn().setBody(handler); }
> } *finally*
> *{ // Fermeture de la strem ValidatingStreamReader validatingStreamReader =
> (ValidatingStreamReader)stream; validatingStreamReader.closeCompletely(); }*
> *}*
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)