Java Compression Library To Support Deflate64

橙三吉。 提交于 2019-12-23 12:41:59

问题


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?


回答1:


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.




回答2:


zlib has a Deflate64 decompressor (in C) in the contrib/infback9 directory. You would need to integrate that into your zip decoder.




回答3:


The 7zip-javabinding library uses JNI to wrap 7zip which supports Deflate64. It provides platform specific solutions, or if you are so inclined they also provide an all-platforms solution.

The libraries are available on Maven Central.

If someone finds a pure Java solution please post another answer! :-)



来源:https://stackoverflow.com/questions/34299045/java-compression-library-to-support-deflate64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!