What are the different zlib compression methods and how to force a default value in Java Deflater?

I use DeflaterOutputStream to compress data as part of the archive file file format. Then I use jcl zlib code to unpack this data on the other end. The other end is a J2ME application, so I rely on third-party zip decompression code, not standard Java libraries.

My problem is that some zip and unzip files are just fine, while others are not.

For those that don’t, the compression method in the first byte of data seems to be β€œ5”.

From my reading in zlib, I understand that the default value of '8' indicates the default deflation method. Any other value is unacceptable to the decompressor.

What I would like to know:

  • What does "5" mean?
  • Why has DeflaterOutputStream been using various compression methods for some time?
  • Can I stop it from doing this?
  • Is there any other way to generate deflated data that uses only the default compression method?
+3
source share
1 answer

This can help focus what you are looking for.

There is usually a two-byte ZLIB header in front of all your data . As far as I know, the lower 4 bits of the first byte should ALWAYS be 8 . If you initialize your Deflater in nowrap mode, then you will not receive these two bytes at all (although otherwise your other library should expect not to receive them).

3- (, , ). , , 5, , , 8, , .

DeflaterOutputStream, Deflater , Defalter , . - , , , ; offshance, , , .

(. setStrategy()) , , huffman. , , 2 ( , ). , , , , , .

Deflater, . , , , . , (.. ZLIB/Inflater ), ...!

, , , , , , , , / "". , J2ME , zlib, , ...

+6

Source: https://habr.com/ru/post/1709391/


All Articles