• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ruthlessly smash the bug...but where is it?  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need a code review badly. I have a zip class that is using java.util.zip, and everything works great - except when I try to zip something up on Windows (this doesn't happen on Mac).

The bug is that my code is not zipping stuff up the same way ZipGenius, WinZip, or even the IPWorks Java Zip API is doing it. All of these things work, but mine is causing a corrupted ODT file for OpenOffice. My suspicion is that the problem lies somewhere in the relativePath variable, or at least something to do with the directory structure of the zip.

ANY help (and I do mean any) is much appreciated.

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to run your code (ofcourse after changing the TAGFile to File and removing the TAGLogger), it worked fine. I zipped using the class and unzipped using Winzip without any issues.
 
Wesley Baker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to hear! I have had the same results, unless it is an ODT file, which si why I am so confused

This is what I'm doing:
If you have OpenOffice installed, create a Write document with some basic text. Save it and unzip the resulting .ODT file into a folder.

If you take this code (on Windows) and use it to zip up the contents of that folder, the ODT will be corrupt. But if you zip up the contents with Winzip, it will work fine.
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the fix yet, but the specific problem is:

The ODT file is a zip file that looks like this:


Your code generates the output like this:


What I think you need to do is detect if the file to zip is a directory and if it is then get the list of files and add them directly rather than adding the directory and the children.

I have to check what you are actually doing though... and I don't know how that would be different on Windows vs. Mac or Linux...

--This above has to do with the zip(File) and zip(File, String) methods. If you call the zip(File[] ...) methods no extra directory is generated.
[ August 20, 2008: Message edited by: Steve Luke ]
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interestingly - when you zip with your application then unzip then rezip with winZip, it works again...
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. Zip files (not even ones that windows Compression or WinZip makes) don't use the "\" File separator character. they always use "/". So When I changed all the places you had File.separator to "/" I could open the odt files in OpenOffice without a problem.
[ August 20, 2008: Message edited by: Steve Luke ]
 
Wesley Baker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve...I don't know what to say. You have solved what every other Java forum out there couldn't figure out. I've been to Sun, OpenOffice, and NeoOffice forums, and they all couldn't figure it out.

All hail Steve!

Thank you so much, sir.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Happy to help :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!