如何解决org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException(epub mimetype)?
当解压缩zip文件时,我的jboss显示错误。如何解决org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException(epub mimetype)?
错误消息
14:36:20,663 ERROR [STDERR] org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException: unsupported feature data descriptor used in entry mimetype
14:36:20,663 ERROR [STDERR] at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:245)
14:36:20,663 ERROR [STDERR] at java.io.InputStream.read(Unknown Source)
这里的test.epub
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
20 Stored 20 0% 03-18-2013 14:39 2cab616f mimetype
0 Stored 0 0% 03-18-2013 10:42 00000000 META-INF/
265 Defl:N 187 29% 03-18-2013 10:42 4d7842ce META-INF/container.xml
1048 Defl:N 271 74% 03-18-2013 10:42 c04d123d META-INF/encryption.xml
0 Stored 0 0% 03-18-2013 12:05 00000000 OEBPS/
1014 Defl:N 530 48% 03-18-2013 12:05 cb8218d1 OEBPS/9.html
LIB的entrys的一部分:公地压缩-1.4.jar 1.5版本已经显示了同样的错误味精。
有人知道为什么发生错误,我如何解决?
添加代码
public void unzip(InputStream is, File destDir, String charsetName)
throws IOException {
ZipArchiveInputStream zis;
ZipArchiveEntry entry;
String name;
File target;
int nWritten = 0;
BufferedOutputStream bos;
byte[] buf = new byte[1024 * 8];
zis = new ZipArchiveInputStream(is, charsetName, false);
while ((entry = zis.getNextZipEntry()) != null) {
name = entry.getName();
target = new File(destDir, name);
if (entry.isDirectory()) {
target.mkdirs();
} else {
Util.createParentDirectory(target);
target.createNewFile();
bos = new BufferedOutputStream(new FileOutputStream(target));
while ((nWritten = zis.read(buf)) >= 0) {
bos.write(buf, 0, nWritten);
}
bos.close();
debug("file : " + name);
}
}
zis.close();
}
当我使用其他LIB(Java.util.zip),还示出了下面的异常。
java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor
at java.util.zip.ZipInputStream.readLOC(Unknown Source)
at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
发生这种情况是因为你有这个“mimetype”文件附加的“数据描述符”。默认情况下(和规范)只允许DEFLATED文件具有此功能,但是您已将其保存在STORED(解压缩ZIP中的文件)。
只需使用allowStoredEntriesWithDataDescriptor = true构造您的ZipArchiveInputStream即可。
public ZipArchiveInputStream(InputStream inputStream,
String encoding,
boolean useUnicodeExtraFields,
boolean allowStoredEntriesWithDataDescriptor)
好的答案!我有同样的问题,但与“java.util.zip.ZipInputStream”。有没有一种方法来指定类似“allowStoredEntriesWithDataDescriptor”在我的情况?谢谢 –
不幸的是,对于java.util.zip来说这似乎不可行:https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/util/zip/ZipInputStream。 Java的#L310 – mikestaub
你可以发布Java代码吗? – NEO
我用它编辑了我的问题。 –