title: How to pass byte[] array from InputStrem to OutputStream?
body: <p>I have stored my <code>image as mediumblob</code> in database</p>
  
  <p>In my Image bean class I have store photo property as byte[] like</p>
  
  <pre><code>private byte[] photo;
  
  // getter and setter method for photo
  </code></pre>
  
  <p>I get image from database using to store in Image bean class</p>
  
  <pre><code>image.setPhoto(resultset.getBinaryStreams(1));
  </code></pre>
  
  <p>then i get the image in Servlet as:</p>
  
  <pre><code>InputStream input = null;
  OutputStream output = null;
  try {
      input = new ByteArrayInputStream(image.getPhoto());
  
      output = // What type of stream should I use here
  
      byte[] buffer = new byte[10240];
      int length;
      while ((length = input.read(buffer)) &gt; 0) {
          output.write(buffer, 0, length);
      }
  } finally {
      output.flush();
      input.close();
  }
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>WHat should I write at output line to show photo using response.getOutputStream or something else?</li>
  <li>Is this method correct or is there any better way?</li>
  </ol>