camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Tombs <cyan.s...@gmail.com>
Subject Re: Freeing objects returned by type converter
Date Fri, 07 Jan 2011 15:14:01 GMT
On 1/7/11, James Strachan <james@fusesource.com> wrote:
> On 7 January 2011 14:51, David Tombs <cyan.spam@gmail.com> wrote:
>> Hello all,
>>
>> I have recently started using camel and it's fantastic. Thanks for all
>> your hard work, committers.
>
> Thanks!
>
>> One issue I came across is whether I should free or close objects
>> returned by a type converter. For example, I have a class that reads
>> some binary data from an InputStream so I wrote a custom Processor
>> that does this:
>>
>> InputStream productStream = exchange.getIn().getBody(InputStream.class);
>>
>> It appears that I need to call close() on productStream or else my
>> file consumer was leaving open handles to the source files. Is this
>> always the case? If the body was already an InputStream, would calling
>> close() be harmful? Am I doing something wrong?
>>
>> I couldn't find anything in the documentation regarding this--type
>> converters were always used to convert to Strings in examples.
>
> Once you've created the stream, its up to you to close it. So you
> might want to create a little helper class to make sure you always
> call close on it. I guess we could add a little helper class to Camel
> to make it a bit easier to use streams and ensure they get closed.
>
> --
>
> --
> James

Thanks for the quick reply, James.

One remaining question: how does this work if the body was already an
InputStream? Would a type converter even be used in that case? Would
the IS I get back be a clone of the "real" IS or something like that?

David

-- 
Wise men _still_ seek Him.

Mime
View raw message