title: How to Cache InputStream for Multiple Use
body: <p>I have an InputStream of a file and i use apache poi components to read from it like this:</p>
  
  <pre><code>POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
  </code></pre>
  
  <p>The problem is that i need to use the same stream multiple times and the POIFSFileSystem closes the stream after use.</p>
  
  <p>What is the best way to cache the data from the input stream and then serve more input streams to different POIFSFileSystem ?</p>
  
  <p>EDIT 1:</p>
  
  <p>By cache i meant store for later use, not as a way to speedup the application. Also is it better to just read up the input stream into an array or string and then create input streams for each use ?</p>
  
  <p>EDIT 2:</p>
  
  <p>Sorry to reopen the question, but the conditions are somewhat different when working inside desktop and web application. 
  First of all, the InputStream i get from the org.apache.commons.fileupload.FileItem in my tomcat web app doesn't support markings thus cannot reset. </p>
  
  <p>Second, I'd like to be able to keep the file in memory for faster acces and less io problems when dealing with files.</p>