There's nothing wrong with the code, but everyone sees that. So perhaps the problem lies in your web server - tomcat or whatever you're using. The problem with these errors is that there's no stack trace available so its hard to figure out where the issue actually is. After looking at the StreamingResolution, I see that it uses PrintWriter to send back the output for the Reader. Perhaps you can override stream method and use ServletOutputStream instead of PrintWriter, although you're passing InputStream so it wouldn't apply. Somewhere down the line, there is too much buffering going on. I've written a video download ActionBean some years ago; it was sending 100MB files with no problems. The code is below and is identical to yours. How much memory to give to your application engine?

                return new StreamingResolution("application/octet-stream") {
                    protected void stream(HttpServletResponse response) throws Exception
                        {
                            String sp = File.separator;
                            InputStream in = new FileInputStream(video.getLocation() + sp + video.getFilename());
                            try
                                {
                                    OutputStream out = response.getOutputStream();

                                    byte[] buf = new byte[1024 * 65];
                                    int size = 0;

                                    while ((size = in.read(buf)) > 0)
                                        out.write(buf, 0, size);
                                }
                            finally
                                {
                                    in.close();
                                }
                        }
                }.setFilename(video.getOriginalFilename());
            }


Daniil

Radim wrote:
Od: "Nikolaos Giannopoulos" <nikol...@brightminds.org>
Komu: Stripes Users List <stripes-users@lists.sourceforge.net>
Datum: 27.07.2010 18:29
Předmět: Re: [Stripes-users] File Download

Radim,


Radim wrote:
    
Hi,
first, excuse my english. I'm just a beginner.
  
      
Your English is just fine ;-)

    
I have a problem with file download. I'm trying to do file upload and download to/from server. File upload works just fine. But I have a probelm with download. I used StreamingResolution with InputStream. Something like this:

    public Resolution get() {
        InputStream is = null;
        try {
            is = new FileInputStream(new File(filePath));
  
      
It is quite amazing that there are so many code examples and questions 
pertaining to reading input streams and not wrapping them in buffered 
input streams all over the net and even in some books. Even if this 
doesn't fix your issue it will be HUGE in improving the reading of files 
a fraction of the size of the ones you are using.

Something like (off the top of my head):
BufferedInputStream is = new BufferedInputStream(new FileInputStream(new 
File(filepath)));

The wonderful thing about OO is that from that point onward "is" is just 
an InputStream so the rest of your code need not change... .

    
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MyActionBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new StreamingResolution(fileType, is);
    }

But if the file is larger than something around 70 or 90 MB, java throws "java.lang.OutOfMemoryError: Java heap space". It seems like Java is trying to load whole file to RAM and then send it to browser. But I would like to work with large files - 2 GB.
  
      
Although I haven't looked at the code of StreamingResolution I imagine 
just by its name that it will chunk read and send the contents of the 
input stream otherwise it wouldn't be called StreamingResolution. 
Buffering is probably your problem or you are hitting this bug (which 
buffering might fix):

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6478546
    

I tried the version with BufferedInputStream and it looks same. 
The server just send first 70 - 90 MB of file and then throws 
java.lang.OutOfMemoryError: Java heap space.


  
BTW what are your JVM settings / options? e.g. your min heap, max heap, 
etc....
    

I'm not sure, but in Glassfish is: JVM Settings -> JVM Options -> "-Xmx512m".

  
Is there any way to send large file to browser?
  
      
Well there is the "obvious" way. Provide the user a URL to it and let 
the web browser handle it. But this requires some conditions such as that:
a) The file is in a place that the web / app server can directly access 
it (i.e. not in the database)
b) A URL can be formed to it (some people have issues here in that they 
want to protect the file and hence stream it).
    

Yes, I probably will do it this way. But I need some kind of security. Some 
files can be available to specific users. Maybe randomly generated names 
of files and periodically renaming will do the thing.

  
Out of curiosity what are you streaming that is 70-90MB. I frequently 
    

I tried this with 200 MB large file. But I need to send even larger files. 2 - 3 GB.

  
see people new to Java or a framework and it appears the first thing 
they want to stream is massive files. Files that large should ideally be 
handled by the web / app server... and in the process it improves 
overall performance all around because they typically are better coded / 
optimized to handle it.

HTH,

--Nikolaos

    
Thanks,
Radim

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

  
      
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

    

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users
  
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to