javazipcompressiondeflateapache-commons-compress

Java Compression Library To Support Deflate64


Looking for an alternative compression java library to Apache Commons Compress (https://commons.apache.org/proper/commons-compress/). Commons Compress throws an error when trying to read a zip entry that was compressed using "ENHANCED_DEFLATED" which is deflate64. Here is sample excerpt that throws the exception.

public void doRecurseZip(File inputFile)
        throws IOException{
    ZipFile srcZip = null;
    srcZip = new ZipFile(inputFile);

    final Enumeration<ZipArchiveEntry> entries = srcZip.getEntries();
    while (entries.hasMoreElements()) {
        final ZipArchiveEntry srcEntry = entries.nextElement();
        String entryFilename = srcEntry.getName();
        String entryMimetype = "application/octet-stream";
        boolean canRead = srcZip.canReadEntryData(srcEntry);
        InputStream zipStream = srcZip.getInputStream(srcEntry);
        zipStream.close();
    }
    srcZip.close();
}

Here is the relevant part of the stack trace:

org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException: unsupported feature method 'ENHANCED_DEFLATED' used in entry test.docx at org.apache.commons.compress.archivers.zip.ZipUtil.checkRequestedFeatures(ZipUtil.java:357) at org.apache.commons.compress.archivers.zip.ZipFile.getInputStream(ZipFile.java:404) at ZippingAround.doRecurseZip(ZippingAround.java:23)

Does anyone know of another zip library that could replace Commons Compress, or possibly work in conjunction with it for the deflate64 compression method?


Solution

  • In February 2018, Apache released Compress v1.16 which includes support for ENHANCED_DEFLATED, ie. Deflate64. I needed this support and found that it seems to work.