【发布时间】:2017-02-15 07:24:39
【问题描述】:
这是我的测试代码,问题是resultLength != original.length,结果数组和原数组一样,不应该是压缩解压后的吗?
public static void main(String[] args) {
// generateTyreAlarmEvent()
byte[] original = {10, 17, 97, 98, 99, 100, 101, 102, 103, 104, 105, 103, 107, 108, 109, 110, 111, 112, 113, 16, 2, 24, -50, -1, -113, -59, 5, 34, 20, 8, -35, 1, 16, 40, 24, -34, 1, 32, 60, 40, -33, 1, 48, 80, 56, -32, 1, 64, 100, 42, 16, 8, 2, 16, 1, 24, 3, 32, 0, 40, 1, 48, 1, 56, 1, 64, 0};
byte[] buffer = new byte[original.length];
Deflater compresser = new Deflater();
compresser.setInput(original);
compresser.finish();
int compressedLen = compresser.deflate(buffer);
compresser.end();
Inflater decompressor = new Inflater();
decompressor.setInput(buffer, 0, compressedLen);
byte[] result = new byte[original.length];
int resultLength = 0;
try {
resultLength = decompressor.inflate(result);
} catch (DataFormatException e) {
}
decompressor.end();
// the problem is resultLength(63) != original.length(67), and result array is same as original array
}
原来的字节数组是(len is 67):
{10, 17, 97, 98, 99, 100, 101, 102, 103, 104, 105, 103, 107, 108, 109, 110, 111, 112, 113, 16, 2, 24, -50, -1, -113, -59, 5, 34, 20, 8, -35, 1, 16, 40, 24, -34, 1, 32, 60, 40, -33, 1, 48, 80, 56, -32, 1, 64, 100, 42, 16, 8, 2, 16, 1, 24, 3, 32, 0, 40, 1, 48, 1, 56, 1, 64, 0}
结果是(len 为 63):
{10, 17, 97, 98, 99, 100, 101, 102, 103, 104, 105, 103, 107, 108, 109, 110, 111, 112, 113, 16, 2, 24, -50, -1, -113, -59, 5, 34, 20, 8, -35, 1, 16, 40, 24, -34, 1, 32, 60, 40, -33, 1, 48, 80, 56, -32, 1, 64, 100, 42, 16, 8, 2, 16, 1, 24, 3, 32, 0, 40, 1, 48, 1}
谢谢!
【问题讨论】: