title: Reading from response body multiple times in Apache HttpClient 4.x
body: <p>I'm using the Apache HttpClient 4.2.3 in my application. We store the response of an HTTP call like so:</p>
  
  <pre><code>HttpResponse httpResponse = (DefaultHttpClient)httpClient.execute(httpRequest);
  </code></pre>
  
  <p>The response body is an InputStream in the 4.x API:</p>
  
  <pre><code>InputStream responseStream = httpResponse.getEntity().getContent();
  </code></pre>
  
  <p>My problem is I need to read the response body as a string and as a byte[] at various points in the application. But the InputStream used by Apache is an EofSensorInputStream, which means once I reach the stream EOF, it gets closed. Is there anyway I can get the string and byte[] representations multiple times and not close the stream?</p>
  
  <p>I've already tried <a href="https://stackoverflow.com/questions/5923817/how-to-clone-an-inputstream">wrapping the byte array in a new ByteArrayInputStream</a> and setting that as the request body, but it doesn't work since my response body can reach a few gigs. I've also tried <a href="https://stackoverflow.com/questions/12107049/how-can-i-make-a-copy-of-a-bufferedreader">this</a>, but I noticed the original response stream still gets closed.</p>
  
  <p>Any pointers would be welcome.</p>
  
  <p>EDIT: On a related note, it would be also be great if I could find the length of the InputStream either without consuming the stream or by reversing the consumption.</p>