[ 
https://issues.apache.org/jira/browse/CAMEL-6294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13634794#comment-13634794
 ] 

Willem Jiang commented on CAMEL-6294:
-------------------------------------

If you need to read the StreamCache again, you need to call the reset method.
If you close the CachedOutputStream which uses the temp file to store the 
stream,  you cannot access the stream anymore.
                
> StreamCache doesn't work as expected
> ------------------------------------
>
>                 Key: CAMEL-6294
>                 URL: https://issues.apache.org/jira/browse/CAMEL-6294
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.10.4
>         Environment: Debian 6.0
>            Reporter: Ulrich Kramer
>             Fix For: 2.10.5
>
>
> The following Unittests fail:
> {code}
> package com.sap.camel.util;
> import java.io.InputStream;
> import junit.framework.Assert;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.Message;
> import org.apache.camel.converter.stream.CachedOutputStream;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.impl.DefaultExchange;
> import org.testng.annotations.Test;
> public class StreamCacheBugs {
>       
>       private CamelContext context;
>       public void setUp() {
>               
>               context = new DefaultCamelContext();
>       }
>       @Test
>       public void multipleConvertionsYielsToEmptyBody() throws Exception {
>               Exchange exchange = new DefaultExchange(context);
>               Message msg = exchange.getIn();
>               CachedOutputStream out = new CachedOutputStream(exchange);
>               out.write("Hello World".getBytes());
>               msg.setBody(out.getStreamCache());
>               Assert.assertEquals(msg.getBody(String.class), "Hello World");
>               Assert.assertEquals(msg.getBody(String.class), "Hello World");
>       }
>       @Test
>       public void closingInputStreamYieldsToException() throws Exception {
>               Exchange exchange = new DefaultExchange(context);
>               Message msg = exchange.getIn();
>               CachedOutputStream out = new CachedOutputStream(exchange);
>               for ( int i = 0 ; i < 10000; i++) 
> out.write("0123456789".getBytes());
>               msg.setBody(out.getStreamCache());
>               InputStream in = msg.getBody(InputStream.class);
>               in.read();
>               in.close();
>               msg.getBody(String.class);
>       }
>       
>       @Test
>       public void cachedOutputStreamsShouldBeClosable() throws Exception {
>               Exchange exchange = new DefaultExchange(context);
>               Message msg = exchange.getIn();
>               CachedOutputStream out = new CachedOutputStream(exchange);
>               for ( int i = 0 ; i < 10000; i++) 
> out.write("0123456789".getBytes());
>               msg.setBody(out.getStreamCache());
>               out.close();
>               msg.getBody(String.class);
>       }
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to