public static void streamContentToBrowser(HttpServletResponse response,byte[] bytes,String contentType,String fileName) throws IOException {
  setResponseBrowserProxyNoCache(response);
  response.setContentLength(bytes.length);
  if (contentType != null) {
    response.setContentType(contentType);
  }
  if (fileName != null) {
    response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");
  }
  OutputStream out=response.getOutputStream();
  InputStream in=new ByteArrayInputStream(bytes);
  try {
    streamContent(out,in,bytes.length);
  }
 catch (  IOException e) {
    in.close();
    out.close();
    throw e;
  }
  in.close();
  out.flush();
  out.close();
}

public static void streamContentToBrowser ( HttpServletResponse response , byte [ ] bytes , String contentType , String fileName ) throws IOException { setResponseBrowserProxyNoCache ( response ) ; response . setContentLength ( bytes . length ) ; if ( contentType != null ) { response . setContentType ( contentType ) ; } if ( fileName != null ) { response . setHeader ( "Content-Disposition" , "attachment;filename=\"" + fileName + "\"" ) ; } OutputStream out = response . getOutputStream ( ) ; InputStream in = new ByteArrayInputStream ( bytes ) ; try { streamContent ( out , in , bytes . length ) ; } catch ( IOException e ) { in . close ( ) ; out . close ( ) ; throw e ; } in . close ( ) ; out . flush ( ) ; out . close ( ) ; }
stream an array of bytes to the browser this method will close the servletoutputstream when finished
