0

I am getting this error:

java.util.zip.ZipException: invalid CEN header (bad signature)

and I am not quite sure what is the problem, when I search google for CEN header nothing useful is found.

Any help is appreciated, thanks.

Here is the code and it fails on the last line:

ZipFile resourceZip = null;
if (pir.getSource().endsWith("Resources.zip")) 
{
    File temp = new File( "C:\\Users\\nbonnet\\Desktop\\new\\Resources1.zip");
    byte[] bytesFromClob = ClobHelper.bytesFromClob(pir.getContents(),"latin1");
    FileOutputStream out = new FileOutputStream(temp);
    out.write(bytesFromClob);
    out.flush();
    out.close();
    resourceZip = new ZipFile(temp);  // <-- Code fails here
}
10
  • 3
    What is the code you are running? Commented Aug 31, 2012 at 17:59
  • Did you see this page helpdesk.objects.com.au/java/invalid-cen-header which states that the error may be caused by a zip file containing an entry larger than 4GB in size. Commented Aug 31, 2012 at 18:19
  • Also this page bugs.sun.com/bugdatabase/view_bug.do?bug_id=6432010 which suggests that the compression method used to create the zip is not supported by the JDK. Commented Aug 31, 2012 at 18:20
  • I added the code I am running. Also I am 100% sure the file is less than 4GB. As far as the compression ... is there a workaround? Can i tell it to do some other compression? Commented Aug 31, 2012 at 18:29
  • Why are you storing binary data in a CLOB? I would suggest that you compare the data that you're reading from the database with the data that you're putting into it. I'll bet they're different. Commented Aug 31, 2012 at 18:35

1 Answer 1

4

You're writing the file as a regular (non-ZIP) file and then trying to read it back as a ZIP file. That's not going to work. You need to write it with a ZipOutputStream.

Check out this example or this one.

Sign up to request clarification or add additional context in comments.

7 Comments

Right. There's nothing in the code above that would create a zip file.
I have tried that but then I get this error: java.util.zip.ZipException: no current ZIP entry But the whole reason I am writing it out to a zip is because I need to see the entries. I believe it throws this because I am not using out.putNextEntry()..
@Keith - that's one interpretation. Another is that the data in the database is in ZIP format. Of course, as I noted in my comment, it's strange that the data is coming from a CLOB rather than a BLOB.
@kdgregory: true, that's another possibility. If so, the header of the file is getting corrupted somehow (character set conversion?).
Possibly character set conversion, or perhaps the CLOB is rejecting any 0 bytes. I figured I gave the OP enough of a hint ... I suspect there are worse problems to come.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.