3

This is a two part question, really.

Preface: I use WinRAR to compress files. It gives you the option of only compressing certain files. I can filter by file extension so that, say, JPEG files are not compressed, while other files are.

  1. Can this be done with ZIP files in general, or is it only a WinRAR/RAR format capability?

  2. If it is possible do to with the ZIP format, is there a way I can do that using Java's ZipOutputStream class? Or, perhaps using some other ZIP Java implementation?

To clarify, I would like to tell my ZipOutputStream to only compress files with a particular extension. Is this possible?

Thanks

Scott
  • 365
  • 3
  • 8

2 Answers2

3

Yes, you can do it with ZipOutputStream. Before each file (or when you want to change it) call setLevel with a constant from Deflater, in your case Deflater.NO_COMPRESSION. The documentation on this should be clearer.

You could easily make a subclass of ZipOutputStream that overrides putNextEntry to handle this logic.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
1

ZipOutputStream has methods to control if subsequent entries are to be deflated, and with which compression level.

This can also be specified on the ZipEntry level (where it takes precedence).

Thilo
  • 257,207
  • 101
  • 511
  • 656