2 Replies Latest reply on Sep 24, 2009 11:45 AM by kapitanpetko

    Problem with the download of large files

      Hi,


      I have a problem with the download of large files (filesize greater than heap
      space) when using Seam. Without Seam everything works fine. The problem does
      only occur when using the Seam Filter! So I hope anybody can help me with
      this problem.


      In order to reproduce the error, I tried it with the excel example from the
      Seam examples and only adepted the home.xhtml by adding:




      <s:link value="Download" action="#{seamdownload.download()}"/>





      The corresponding bean class:





      @Name("seamdownload")
      public class SeamDownload {
      
           @Logger
           Log log;
           
           public void download() {
                try {
                     FacesContext facesContext = FacesContext.getCurrentInstance();
                     HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
                     
                     //File must be greater than the heap space - otherwise it works fine!
                     FileInputStream fis = new FileInputStream("/home/bhellmann/mup/filestorage/BigFileUpload/largefile.tar");
      
                     response.setContentType("application/pdf");
                     response.setHeader("Content-Disposition", "attachment;filename=\""     + "largefile.tar" + "\"");
                     response.flushBuffer();
                    
                       ServletOutputStream out = response.getOutputStream();
                     int length = 0;
                     int filesize = 0;
                     byte[] b = new byte[2048];
                     while((length = fis.read(b)) > 0) {
                          out.write(b, 0, length);
                          filesize += length;
                     }
                     response.setContentLength(filesize);
                     facesContext.responseComplete();
                } catch (Exception e) {
                     e.printStackTrace();
                }
           }
      }



      Is there any solution for this problem? or any ideas?


      Thanks in advance