Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Writing large files to the servletoutputstream in chunks

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
dear all,

If i have to download a large file, say > 200 mb, from the servlet if i use fileinputsream to read and write to the servletoutputstream i get outofmemory error. how do i split this file into various chunks and write them to the stream?
does using
response.setContentType("application/octet-stream");
solve the problem?
although i tried
outputStream = new GZIPOutputStream(response.getOutputStream(), 10240);
it didnt solve the problem.

thanks
V
 
az ziz
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
can this be solved using the multi-part response? how about the browser compatibility? i read somewhere long back that IE do not understand this response ?

V
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Without knowing how you're copying from one stream to the other it's impossible to help.
 
az ziz
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
i have few pdf files in the file server. This pdf may vary in sizes. i need to let the client download them though the servlet. i receive the file name from the request and read the file using FileInputStream. i write them to the ServletOutputStream.
during this operation i receive OutOfMemoryError.

kindly reply for any other clarification.

V
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
When someone on a Java forum asks about "how you're doing something" it's almost *always* a request for code, or at the *very* least, pseudo-code. Copying a file should use essentially zero memory unless you're doing it wrong. Read into a buffer, write the buffer out, repeat until done. No memory other than the buffer is being used.

Personally, I almost always just use something from commons-io, but it does the exact same thing.

So again, without knowing what you're doing, it's impossible to know what you might be doing wrong.
 
az ziz
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
for your reference, please find the below codes that does the said work.

unnecessary codes are removed

pdfPrintList is the List containing the FileInputStream of the files to be sent to the client.



below code will join the list of pdfs, this will use the itext lib.



thanks
V
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Looks to me like it is the PDF combining that uses all the memory, not the servlet output stream.

Didn't you already write about this problem in the performance forum?

HERE!

WHY in the name of Alan Turing are you coming back with the same problem, after NOT taking the advice in the performance forum.

Bill
 
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic