Hi

Good idea as from Camel 2.12 onwards we have a StreamCachingStrategy
which allows us to safely use CachedOutputStream in components without
forcing spooling to disk on end-users, without them knowing that.

Fell free to log a JIRA ticket.

On Wed, Sep 4, 2013 at 11:14 AM, Franz Paul Forsthofer
<[email protected]> wrote:
> Hello,
>
> the MarschallProcessor currently returns a byte array. This does mean that
> large messages are kept in memory which can lead to performance problems. I
> suggest to use StreamCache instead by using CachedOutputStream instead of
> ByteArrayOutputStream.
>
> To be more concret, instead of
>
>     public void process(Exchange exchange) throws Exception {
>         ObjectHelper.notNull(dataFormat, "dataFormat");
>
>         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
>         Message in = exchange.getIn();
>         Object body = in.getBody();
>
>         // lets setup the out message before we invoke the dataFormat
>         // so that it can mutate it if necessary
>         Message out = exchange.getOut();
>         out.copyFrom(in);
>
>         try {
>             dataFormat.marshal(exchange, body, buffer);
>             byte[] data = buffer.toByteArray();
>             out.setBody(data);
>         } catch (Exception e) {
>             // remove OUT message, as an exception occurred
>             exchange.setOut(null);
>             throw e;
>         }
>     }
>
> we should use
>
>    public void process(Exchange exchange) throws Exception {
>         ObjectHelper.notNull(dataFormat, "dataFormat");
>
>         CachedOutputStream buffer = new CachedOutputStream(exchange,true);
>         Message in = exchange.getIn();
>         Object body = in.getBody();
>
>         // lets setup the out message before we invoke the dataFormat
>         // so that it can mutate it if necessary
>         Message out = exchange.getOut();
>         out.copyFrom(in);
>
>         try {
>             dataFormat.marshal(exchange, body, buffer);
>             out.setBody(buffer.getStreamCache() );
>         } catch (Exception e) {
>             // remove OUT message, as an exception occurred
>             exchange.setOut(null);
>             throw e;
>         }
>     }
>
>
> Regards Franz
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Improvement-Suggestion-for-MarschallProcessor-Use-CachedOutputStream-instead-of-ByteArrayOutputStream-tp5738654.html
> Sent from the Camel Development mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [email protected]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to