This discussion is archived
4 Replies Latest reply: Dec 13, 2010 1:24 AM by 823116 RSS

Zip file produced by Java can't be opened in OS/390 (Mainframe)

823116 Newbie
Currently Being Moderated
A Java program creates a zip file which has to be opened by Pkunzip on mainframe.

The problem is this, mainframe can't open the zip file. But when we open the file in WinRar and rename the one file in it, rename it back to the original name (re-zip the file) it can be opened by Pkunzip.

Here's the zip format spec. : http://www.pkware.com/documents/casestudies/APPNOTE.TXT

according to the spec I tried to find the differences of both files (untouched zip file created by Java and re-zipped file).

the result is as in the picture attached.

I used a file "a.txt" which content is simply "1234567890".

the crc of a.txt is :
DEC : 639479525
HEX : 261DAEE5

the zip file created by my Java program includes 4 sections (I've marked those with a green underscore) :
0x04034b50 <- A. Local file header:
0x02014b50 <- F. Central directory structure:
0x08074b50 <- C. Data descriptor:
0x06054b50 <- I. End of central directory record:

a zip file created by right-clicking a.txt and choosing "add to archive..." has fewer sections.
But that's not important right now, since I know that PKUNZIP on the mainframe does accept archives created by Java and rezipped by WinRar.


The zip files created by java doesn't include
1 - the crc
2 - the compressed file size
3 - the uncompressed file size

in the "local file header". Those 3 are present and set in other parts of the file, though, e.g. in the "central file header signature" section.

And the 'Version made by' flag changes from "14 00" to "17 0b", but I don't think that's the problem PKUNZIP is complaining about.


I've also tried to set the crc and the size explicitly, but the result is the same as described above :
view plaincopy to clipboardprint?
ZipEntry entry = new ZipEntry(fileToBeZipped);
entry.setSize(inputFile.length()); // <-- doesn't affect the "local file header" section
CRC32 crc32 = new CRC32();
...
while ((len = is.read(bytes)) >= 0) crc32.update(bytes, 0, len);
System.out.println("Value of crc after setCRC method : " + entry.getCrc()); // <-- prints 639479525
entry.setCrc(crc32.getValue()); // <-- doesn't affect the "local file header" section

The files' view in a hex editor :
created by Java program http://www.coderanch.com/forums/posts/downloadAttach/1732
re-zipped by WinRar http://www.coderanch.com/forums/posts/downloadAttach/1731

I'm stuck at this point. Does anybody have a clue how to solve this ?

Edited by: user9933068 on Dec 11, 2010 2:13 PM
  • 1. Re: Zip file produced by Java can't be opened in OS/390 (Mainframe)
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    user9933068 wrote:
    A Java program creates a zip file which has to be opened by Pkunzip on mainframe.

    The problem is this, mainframe can't open the zip file. But when we open the file in WinRar and rename the one file in it, rename it back to the original name (re-zip the file) it can be opened by Pkunzip.
    Java doesn't do anything terribly exciting with its zip files.

    Your description above with WinRar suggests the following.
    1. The WinRar doesn't have a problem with it.
    2. By changing the zip itself your target app now works.

    Myself I would suspect Pkunzip as the source of the problem.

    And it seems like you have a simple solution. Use WinRar before sending it off.
  • 2. Re: Zip file produced by Java can't be opened in OS/390 (Mainframe)
    823116 Newbie
    Currently Being Moderated
    Exactly, the target app is Pkunizp running on mainframe.

    The Java program I have to write does a lot of things like sending it over to an sftp site and mailing a notification message. Zipping the file is just one part of a few steps.
    now, I do actually consider using a native program for the job. The finished Java program will run on AIX, I just develop in on Windows. So, I guess AIX has a tool for zipping the file.

    and yes, Winrar opens the Java-created zip file.

    but is it a bug in the Java API, that the header sections doesn't include the crc and size info of the file ?
    WinRar and Windows itself do set the crc etc at the first section of the zip file. (see attachment).
  • 3. Re: Zip file produced by Java can't be opened in OS/390 (Mainframe)
    452196 Journeyer
    Currently Being Moderated
    I've had problems with certain versions of zip utility in the past. The problem is down to the way that the ZipOutputStream writes zip files in a forward-only direction, and doesn't know the size of the entries until they have been written. The ZIP specification make allowance for this kind of thing by allowing the size, compressed size and CRC for an entry to be deferred from the entry's header to a special footer item which follows the entry's data.

    However there have been some ZIP utilities that don't implement this feature of the ZIP specification. I wound up writing my own zip writer which required a file as an output, so it could skip back and write the necessary info into the header. Don't have it to hand, I'm afraid, though you might still find it somewhere on the archives of the old Sun site.
  • 4. Re: Zip file produced by Java can't be opened in OS/390 (Mainframe)
    823116 Newbie
    Currently Being Moderated
    that's a very helpful answer, thanks.

    I think I will go native, that is, try to call a zip program on AIX and Windows with Runtime.exec().

    btw, just tried the jar command (Win Java 1.5) and it doesn't add the info into the header, too.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points