I need to create a zip file and am limited by the following conditions:
- The entries come as byte[] (or ByteArrayOutputStream) and not as File.
- The filenames for the entry can be non-ascii/UTF-8.
- JDK 1.6 or earlier
Since java.util.zip only supports UTF-8 filenames from JDK 1.7 and onward, it seems better to use commons-compress ZipArchiveOutputStream. But how to create a ZipEntryArchive based on a byte array or ByteArrayOutputStream rather than a File?
Thank you!
The following method takes a byte[] as input, produces a zip and returns its content as another byte[]. All is done in memory. No IO operations on the disk. I stripped exception handling for a better overview.
Does this solve your problem?