K.Barad
K.Barad

Reputation: 1016

(JAVA) handling different compression types in zipstreams

I'm currently trying to build a function for hunting down files in nested zips. The general problem I can handle and I've got my code working correctly. The problem I'm having is related to compression formats.

Default zip files are not an issue, I open my zipinputstream, send it to my search function, check for each of the entries if it is a zip file and if so I wrap the inputstream in another zipinputstream and recurse. The problem comes when I have a non standard zip compression.

I would like to make this function much more robust: to be able to detect the compression format of the zip entry, wrap it in the correct deflater, and then wrap that in a zipinputstream so that I can recurse. The problem is I don't know how to decode the compression settings. I also don't know how to handle other zip compression formats.

Any advice on how to make this function more flexible would be helpful. I intend to integrate this into my own personal libraries so will be using this function from all sorts of directions in the future.

Upvotes: 2

Views: 438

Answers (1)

Thorn
Thorn

Reputation: 4057

As far as I know, the only compression algorithm supported by java.util.zip is the standard one. But you can detect the compression algorithm using the ZipEntry getMehod() .

Adding support for other compression algorithms may require some work on your part - unless you can find a library with support for different algorithms. For instance, there is a library for 7zip's LZMA format, but the classes do not extend Decoder or ZipEntry - they just provide an alternative. You would need to extract the nested zip file uncompressed and then use something else to unzip it. This is probably not as clean as you would like.

Upvotes: 2

Related Questions