Is it possible to create a Zip-Archive in Java if I do not want to write the resulting archive to disk but send it somewhere else?
The idea is that it might be a waste to create a file on disk when you want to send the Zip-Archive to a user via HTTP (e.g. from a Database-Blob or any other Data-Store).
I would like to create a
java.util.zip.ZipOutputStream
or a
apache.commons.ZipArchiveOutputStream
where the Feeder would be a ByteArrayOutputStream coming from my Subversion Repository
Yes this is absolutely possible!
Create your Zip entry using the
putNextEntrymethod on theZipOutputStreamthen put the bytes into the file in the zip by callingwriteon theZipOutputStream. For the parameter for that method, thebyte[], just extract them from theByteArrayOutputStreamwith itstoByteArraymethod.And the
ZipOutputStreamcan be sent anywhere, as its constructor just takes anOutputStreamso could be e.g. your HTTP response.