Tag: deflate

非对称java压缩

我有一个数据样本: byte[] b = new byte[]{120, 1, -67, -107, -51, 106, 20, 81, 16, -123, 107, 18, -51, -60, 31, -30, 117, -4, -53, -60, -123, 25, 70, 71, 23, -111, 89, 12, 8, -83, 49, 4, -14, -93, -63, 73, 32, 89, -55, -112, -123, 10, -30, 66, 69, -110, 69, -64, -107, -77, […]

将Java Deflater / Inflater与自定义字典一起使用会导致IllegalArgumentException

以下代码基于java.util.zip.Deflater的javadocs中给出的示例。 我所做的唯一更改是创建一个名为dict的字节数组,然后使用setDictionary(byte [])方法在Deflater和Inflater实例上设置字典。 我看到的问题是,当我用与Deflater完全相同的数组调用Inflater.setDictionary()时,我得到一个IllegalArgumentException。 这是有问题的代码: import java.util.zip.Deflater; import java.util.zip.Inflater; public class DeflateWithDictionary { public static void main(String[] args) throws Exception { String inputString = “blahblahblahblahblah??”; byte[] input = inputString.getBytes(“UTF-8”); byte[] dict = “blah”.getBytes(“UTF-8”); // Compress the bytes byte[] output = new byte[100]; Deflater compresser = new Deflater(); compresser.setInput(input); compresser.setDictionary(dict); compresser.finish(); int compressedDataLength = compresser.deflate(output); // […]

Zlib压缩在Java中使用Deflate和Inflate类

我想尝试在java.util.zip中使用Deflate和Inflate类来进行zlib压缩。 我能够使用Deflate压缩代码,但在解压缩时,我遇到了这个错误 – Exception in thread “main” java.util.zip.DataFormatException: unknown compression method at java.util.zip.Inflater.inflateBytes(Native Method) at java.util.zip.Inflater.inflate(Inflater.java:238) at java.util.zip.Inflater.inflate(Inflater.java:256) at zlibCompression.main(zlibCompression.java:53) 这是我目前的代码 – import java.util.zip.*; import java.io.*; public class zlibCompression { /** * @param args */ public static void main(String[] args) throws IOException, DataFormatException { // TODO Auto-generated method stub String fname = “book1”; FileReader infile […]

在处理给定的数据集时,如何为zlib’setDictionary’找到一个好的/最佳的字典?

我有一组(巨大的)类似的数据文件。 该集合不断增长。 单个文件的大小约为10K。 每个文件都必须自己压缩。 压缩是使用zlib库完成的,该库由java.util.zip.Deflater类使用。 使用setDictionary将字典传递给Deflate算法时,我可以提高压缩率。 有没有办法(算法)找到’最佳’字典,即具有整体最佳压缩比的字典? 请参阅zlib手册