How to fix org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException(epub mimetype)?
exception, java, zip
Solution
This happens because you have what is called, "data descriptor" attached to this "mimetype" file. By default (and spec,) only DEFLATED files are allowed to have this, but you have it on STORED (uncompress file within the ZIP.)
Just construct your ZipArchiveInputStream with allowStoredEntriesWithDataDescriptor=true.
public ZipArchiveInputStream(InputStream inputStream,
String encoding,
boolean useUnicodeExtraFields,
boolean allowStoredEntriesWithDataDescriptor)
Problem
My jboss shows the error while zip file is being on unzip process. Error message ``` 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) ``` here's a part of entrys of 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 : commons-compress-1.4.jar 1.5 version has showed the same error msg. Anybody know why the error occurred and how I fix it?? Add the code ``` 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(); } ``` When I use other LIB(Java.util.zip), also shows the Exception below. ``` 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) ```