title: byte [] to image for download
body: <p>I have one image file which i am converting to <code>byte[]</code> and saving it in database while user click on file link from UI that file has to be downloaded to download i have written one method </p>
  
  <pre><code>public void downloadDeclarationForm(HttpServletRequest request, 
                                        HttpServletResponse response) throws IOException {
      int payrollId = RequestUtils.getBrowsePayroll(request);
      Payroll payroll = itConfigManager.getObjectOrNull(Payroll.class, payrollId);
      int year = payrollManager.getYear(payroll.getFromDate());
      int id = NumberUtils.toInt(request.getParameter("id"));
      try {
          byte[] byteBuf = itConfigManager.getDeclarationFormBytes(id, year);
          ControllerUtils.writeFileUploadHeaders(response, 
                                   itConfigManager.getFileName(id, year), byteBuf.length);
          //response.setContentType("image/jpeg");
          OutputStream stream = new ByteArrayOutputStream();
  
          response.getOutputStream().write(byteBuf);
          response.getOutputStream().flush();
          response.getOutputStream().close();
      } catch (Exception e) {
          e.printStackTrace();
          response.getOutputStream().print(
                  "Error while fetching attachment..");
      } finally {
          response.getOutputStream().close();
  
      }
  
  }
  </code></pre>
  
  <p>While i am clicking on the download link it opening the download window even in that window file name is coming correct with correct extension but its not opening the file if i am saving that file to disk and try to open its not opening can any one help me ?</p>