title: How can I get an Input Stream from HSSFWorkbook Object
body: <p>I want my web application users to download some data as an Excel file. </p>
  
  <p>I have the next function to send an Input Stream in the response object.  </p>
  
  <pre><code>public static void sendFile(InputStream is, HttpServletResponse response) throws IOException {
          BufferedInputStream in = null;
          try {
              int count;
              byte[] buffer = new byte[BUFFER_SIZE];
              in = new BufferedInputStream(is);
              ServletOutputStream out = response.getOutputStream();
              while(-1 != (count = in.read(buffer)))
                  out.write(buffer, 0, count);
              out.flush();            
          }   catch (IOException ioe) { 
              System.err.println("IOException in Download::sendFile"); 
              ioe.printStackTrace();
          } finally {
              if (in != null) {
                  try { in.close(); 
                  } catch (IOException ioe) { ioe.printStackTrace(); }
              }   
          }
      }
  </code></pre>
  
  <p>I would like to transform my HSSFWorkbook Object to an input stream and pass it to the previous method. </p>
  
  <pre><code>public InputStream generateApplicationsExcel() {
      HSSFWorkbook wb = new HSSFWorkbook();
      // Populate the excel object
      return null; // TODO. return the wb as InputStream 
  }
  </code></pre>
  
  <p><a href="http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html" rel="noreferrer">http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html</a></p>