我有一个压缩的文件。Inflater获取压缩方法
使用Inflater
类,我可以解压缩它,但是当我使用Deflater
再次压缩它时,两个文件都不相同。
我已经试图改变压缩级别最好...
public static String compress(byte[] rawData)
{
Deflater compressor = new Deflater();
byte[] byteBuffer = new byte[1024];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(
rawData.length);
compressor.setInput(rawData);
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.finish();
while (!compressor.finished())
{
outputStream.write(byteBuffer, 0,
new Integer(compressor.deflate(byteBuffer)));
}
return new String(outputStream.toByteArray());
}
...,结果是更接近原始。
这里是我的吹气代码:
public static String decompress(byte[] compressed)
throws DataFormatException
{
Inflater decompressor = new Inflater();
byte[] byteBuffer = new byte[1024];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(
compressed.length);
decompressor.setInput(compressed);
while (!decompressor.finished())
{
outputStream.write(byteBuffer, 0,
new Integer(decompressor.inflate((byteBuffer))));
}
return new String(outputStream.toByteArray());
}
我如何找出哪些选项已初步被以重建从解压一个原始文件使用?我新近压缩的文件不符合规定。
出于好奇,你为什么需要这样做? – Boann 2014-09-12 17:25:38
@Boann:我得到了一个带有脚本的压缩文件,我想要修改和重建。没有关于它的详细信息 – BullyWiiPlaza 2014-09-12 17:34:02
@ user3764804但是,为什么它应该使用什么精确的压缩器设置,只要它可以通过任何兼容的解压缩器进行解压缩? – Boann 2014-09-12 17:35:42