Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help w/ZIP archives: why no compression?

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Snigdha Solanki
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic