问题
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