提交 53c890d9 authored 作者: Thomas Mueller's avatar Thomas Mueller

Compressing large blocks of data didn't work when using the "Deflate" compression algorithm.

上级 73d5ca84
......@@ -59,14 +59,15 @@ public class CompressDeflate implements Compressor {
deflater.finish();
int compressed = deflater.deflate(out, outPos, out.length - outPos);
while (compressed == 0) {
// the compressed data is 0, meaning compression didn't work
// the compressed length is 0, meaning compression didn't work
// (sounds like a JDK bug)
// try again, using the default strategy and compression level
strategy = Deflater.DEFAULT_STRATEGY;
level = Deflater.DEFAULT_COMPRESSION;
return compress(in, inLen, out, outPos);
}
return compressed;
deflater.end();
return outPos + compressed;
}
public int getAlgorithm() {
......@@ -78,7 +79,10 @@ public class CompressDeflate implements Compressor {
decompresser.setInput(in, inPos, inLen);
decompresser.finished();
try {
decompresser.inflate(out, outPos, outLen);
int len = decompresser.inflate(out, outPos, outLen);
if (len != outLen) {
throw new DataFormatException(len + " " + outLen);
}
} catch (DataFormatException e) {
throw Message.getSQLException(ErrorCode.COMPRESSION_ERROR, e);
}
......
......@@ -42,7 +42,7 @@ public interface Compressor {
* @param inLen the number of bytes to compress
* @param out the output area
* @param outPos the offset at the output array
* @return the size of the compressed data
* @return the end position
*/
int compress(byte[] in, int inLen, byte[] out, int outPos);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论