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

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

> 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).

Out of curiosity what are you streaming that is 70-90MB. I frequently 
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

Reply via email to