Author Topic: Exception : Expected central directory entry not found  (Read 14268 times)

jeromeh

  • Newbie
  • *
  • Posts: 2
    • View Profile
Exception : Expected central directory entry not found
« on: May 23, 2011, 06:24:12 PM »
Dear,

I'm using Zip4j in a workflow software and the integration is made with groovy.
The following script (below the exception in this message) generate from time to time the below exception.
For some zip files it works fine, for other it don't.

Do you know where it can comes from ?

Thanks & Regards,

Jerome



---------------------------------------------------------
Exception :

Expected central directory entry not found (#1) net.lingala.zip4j.exception.ZipException: Expected central directory entry not found (#1) at net.lingala.zip4j.core.HeaderReader.readCentralDirectory(HeaderReader.java:214) at net.lingala.zip4j.core.HeaderReader.readAllHeaders(HeaderReader.java:83) at net.lingala.zip4j.core.ZipFile.readZipInfo(ZipFile.java:387) at net.lingala.zip4j.core.ZipFile.isEncrypted(ZipFile.java:667) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at Script1.run(Script1.groovy:25) at org.ow2.bonita.util.GroovyUtil.evaluateGroovyExpression(SourceFile:427)


----------------------------------------------------------
Code :

import org.ow2.bonita.facade.*
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.Arrays;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

QueryRuntimeAPI queryRuntimeAPI = apiAccessor.getQueryRuntimeAPI()

attachment = queryRuntimeAPI.getAttachments(processInstance.getUUID(),"xmlzip")
File file1 = new File("c:\\TMP\\myfile.zip")
file1 << queryRuntimeAPI.getAttachmentValue(attachment)

ZipFile zipFile = new ZipFile(file1);

if (zipFile.isEncrypted())
{
   // if yes, then set the password for the zip file
   zipFile.setPassword("xxxxxxx");
}
         
// Specify the file name which has to be extracted and the path to which
// this file has to be extracted
zipFile.extractAll("c:\\TMP\\");

-----------------------------------------------------------

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 403
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #1 on: May 25, 2011, 06:31:34 PM »
Hi Jerome,

Every entry in a zip file has a signature. This error means that this signature was not found in the zip headers for the 2nd entry in the zip file. This is because of a corrupt zip file. Could you please let me know:

  • If you are able to open this zip file with any other zip tools (Winzip,7Zip,etc)
  • Was this zip file created by Zip4j?
  • If yes, could you post the code which you used to create the zip file and also a sample zip file. If not, you have to look into the application which created this zip file

Thanks

jeromeh

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #2 on: May 26, 2011, 08:16:32 AM »
Hi,

This file has not been created zip Zip4j. Nevertheless, I have no issue to open it with winzip or any other tool.
Is Zip4j more sensible ? Do you know if there is a way to bypass that ?

Thanks for your support,

Jerome

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 403
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #3 on: May 26, 2011, 10:21:55 AM »
Hi Jerome,

Can you please attach a sample zip file for which you have problems extracting? This would help me to debug this issue

Thanks

Srikanth

tanwar.amar@gmail.com

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #4 on: January 08, 2012, 08:59:45 PM »
Hi,

I am getting same error while using same API to unzip password protected zip file in android.

Need your help in figuring out the solution to the problem.

Please find attached the zip file.
Password to open this file is test123

Looking forward to your reply.

Thanks,
Amar Tanwar.

tanwar.amar@gmail.com

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #5 on: January 09, 2012, 06:12:52 AM »
Addition:

I am able to open this file in Winzip.

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 403
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #6 on: January 09, 2012, 02:13:07 PM »
Hi,

As described in my first reply to OP, Zip4j was not able to find the central directory at the specified location.

Which version of Winzip did you use to test the zip file? I just tried extracting it in Winzip (version 10 and 16) but got an error message.



I was able to open the file in 7Zip, but 7Zip has a different mechanism to read central directory. Zip4j on the other hand reads the central directory at the location mentioned in End Of Central Directory header. Which is the wrong location in this case.

Issue is with the application which you used to create the Zip file. Did you use Zip4j to create the Zip file?

Regards,
Srikanth

Yoteco

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Exception : Expected central directory entry not found
« Reply #7 on: March 11, 2016, 03:18:27 PM »
Hi

I also encounter the same problem. I tried different ZIP Tools (zip4j included) and the extraction never works except when using zip4j to create the archive. My problem is that I cannot expect the users to use zip4j to create big archives.

My question: is there a way to change the source code so that it is less restrictive (like JAR) while unzipping a big archive? I mean is there a way to unzip an big archive even when the headers are not available as expected?

Thanks for you help!