title: Using Stream Cache With Apache Camel
body: <p>I m using stream caching with this example below.</p>
  
  <p>I have three routes.</p>
  
  <p>First, I used the split streaming with a token "\n", reading a file splitted by line. </p>
  
  <pre><code>     &lt;route id="SPLIT-FLOW" streamCache="true"&gt;
          &lt;from uri="file:src/data/forSplitCaching?noop=true"/&gt;
          &lt;split streaming="true"&gt;
              &lt;tokenize token="\n"/&gt;
              &lt;to uri="direct:PROCESS-BUSINESS"/&gt;
          &lt;/split&gt;
      &lt;/route&gt;
  </code></pre>
  
  <p>Then I made a business process : </p>
  
  <pre><code>    &lt;route id="PROCESS-BUSINESS" streamCache="true"&gt;
          &lt;from uri="direct:PROCESS-BUSINESS"/&gt;
          &lt;bean ref="ProcessBusiness" method="dealRecord"/&gt;
          &lt;to uri="direct:STREAM-CACHING"/&gt;
      &lt;/route&gt;
  
      public class ProcessBusiness {
  
       public String dealRecord(@Body String body){
       System.out.println(body);
       return body;
  }
  </code></pre>
  
  <p>And Finally, </p>
  
  <pre><code>    &lt;route id="STREAM-CACHING"&gt;
          &lt;from uri="direct:STREAM-CACHING"/&gt;
          &lt;bean ref="ProcessStreamCaching" method="usingStream"/&gt;
          &lt;setHeader headerName="CamelFileName"&gt;
              &lt;simple&gt;${header.CamelFileName}.${header.CamelSplitIndex}   &lt;/simple&gt;
          &lt;/setHeader&gt;
          &lt;to uri="file:src/out"/&gt;
      &lt;/route&gt;
  
     public class ProcessStreamCaching {
  
       public String usingStream(Exchange exchange){
       Object o = exchange.getIn().getBody(StreamCache.class);
       return  o.toString();
      }
  </code></pre>
  
  <p>I wanted to get the whole file in this process (<code>ProcessStreamCaching</code>).</p>
  
  <p>How can i correctly use the stream cache ?</p>
  
  <p>The file before splitting contain :</p>
  
  <pre><code>XXXXX
  YYYYY
  ZZZZZ
  AAAAAAAAAAAAA
  BBBBBBBB
  CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  SSSSSSSSSSSSSSSS
  SSQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
  ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
  Z
  </code></pre>
  
  <p>I thought that the stream cache was able to put all line of the file in a cache, and i can retrieve these lines.</p>
  
  <p>How can I see what is placed in the cache ?  </p>
  
  <p>I thought when i add  <code>streamCache="true"</code> at this route <code>&lt;route id="SPLIT-FLOW" &gt;</code>, each line of the splitter will be placed on the cache. (or may be the whole file) </p>
  
  <p>At the last process <code>ProcessStreamCaching</code>, if I wanted to reload the  <code>inputStream</code> from the beginning , but at this process i can't because i have already read the <code>inputStream</code>.</p>
  
  <p>I want to keep reading the file with streaming line per line, but at on process  I need to read for exemple the first line , that s why i wanted to use the stream cache , who allows me to browse the file from the beginning.</p>
  
  <p>May be I misunderstand the Stream Cache.</p>