This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Need help w/ZIP archives: why no compression? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help w/ZIP archives: why no compression?" Watch "Need help w/ZIP archives: why no compression?" New topic
Author

Need help w/ZIP archives: why no compression?

Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
I've been goofing around with the java ZIP classes today, and I've got a small problem I was hoping someone could help me with. The code below is supposed to archive multiple files at once. And it does, but it doesn't compress them, even when I specifically say to deflate the files. Can anyone see an error I missed?
Thanks!


There's nothing more dangerous than a resourceful idiot. ---Dilbert
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I just ran a test, and the files look compressed to me - the same sizes I get if I create a zip of the same files "by hand" so to speak, averaging aroung 50% for a group of .java and .class files. That's for any compLevel for 1-9. If I use 0 I get no compression. What value are you using?


"I'm not back." - Bill Harding, Twister
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
Try setting the compression level by calling method setLevel(int level). By default, the compression level is set to Deflater.DEFAULT_COMPRESSION. Change it to Deflater.BEST_COMPRESSION and try.
Hope this helps.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
No kidding? When giving it a level of 9, I was getting savings of only about 3k!
Originally posted by Jim Yingst:
I just ran a test, and the files look compressed to me - the same sizes I get if I create a zip of the same files "by hand" so to speak, averaging aroung 50% for a group of .java and .class files. That's for any compLevel for 1-9. If I use 0 I get no compression. What value are you using?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
3K compared to how many?
What sort of files were you compressing? Binary files like jpg, gif, exe often don't compress much. (Particularly the images - they're often already pretty well compressed.) Also, larger files often have better compression ratios than short ones. Try big text files. Heck, make a text file with the same line 1000 times or so. If you don't get good compression on that one, you know something's very wrong.
Also, what JDK are you using? It's possible some of the older ones aren't as good here. I was using 1.4.1 on Win XP.
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
It was a 300K .pdf. I was on '95 using JDK 1.4.0_01. I tried it out on some different PDF files yesterday, and it worked.
Originally posted by Jim Yingst:
3K compared to how many?
What sort of files were you compressing? Binary files like jpg, gif, exe often don't compress much. (Particularly the images - they're often already pretty well compressed.) Also, larger files often have better compression ratios than short ones. Try big text files. Heck, make a text file with the same line 1000 times or so. If you don't get good compression on that one, you know something's very wrong.
Also, what JDK are you using? It's possible some of the older ones aren't as good here. I was using 1.4.1 on Win XP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help w/ZIP archives: why no compression?