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
Joined: Dec 17, 2008
Posts: 50
posted
0
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 ?
Without knowing how you're copying from one stream to the other it's impossible to help.
az ziz
Ranch Hand
Joined: Dec 17, 2008
Posts: 50
posted
0
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.
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
Joined: Dec 17, 2008
Posts: 50
posted
0
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.