views:

553

answers:

1

I'm trying to zip a large number of pdf files (stored as BLOBs in the DB) and then return the zip as an attachment to the user.

What's the best way to do this without running into memory issues?

Another note: I actually need to merge some PDFs prior to adding them to the ZipOutputStream. Therefore, a couple PDFs will need to be stored in memory at a time.

I assume it would be best to then store them as temporary files on the server before zipping them all?

A: 

You can create zip files in memory in Java using ZipOutputStreams.

See http://www.exampledepot.com/egs/java.util.zip/CreateZip.html

Thorbjørn Ravn Andersen
Yes, but these files could potentially be *very* large. Plus many people could be requesting them at once. Therefore, I'm more interested in doing it using the least memory possible at any given point in the process.
Zack
You can use ZipOutputStream to stream them out to the client.
Tom Hawtin - tackline