title: How to put data in Java InputStream?
body: <p>My current application requires to read data and enable user to download it as a file. 
  Server side code is similar to this : <a href="https://stackoverflow.com/a/55788/3192744">https://stackoverflow.com/a/55788/3192744</a>
  I need data inside InputStream, my current method to get InputStream is:</p>
  
  <pre><code>    InputStream getIStream(){
      StringBuilder sb = new StringBuilder();
      String temp = “”;
      while(//there is data to be read from database//){
              temp = //partial data or one entry from database
              //some other modification in temp
              sb.append(temp).append(“\n”);
      }
      exampleString = sb.toString();
      InputStream stream = new ByteArrayInputStream(exampleString.getBytes());
      }
  </code></pre>
  
  <p>This method works for now since my data is very small, about 1000 String, each of about 100 chars, hence 100000 chars. Still, before I start download, I need to wait for entire data to be written in one string. Also as my data size increases it won't fit in one string.
  So Is it possible to keep updating InputStream inside the while loop.</p>
  
  <p>And to read this data on server side, I am waiting the method to return InputStream, so is it possible to send InputStream as method argument, and keep reading from it while it is being updated.</p>
  
  <p>Basically I want to implement something like a pipe, where modified strings from database output are being sent, and on the receiving end data is being put in the file for user to download, and download process for user can start while data is being read from database.</p>