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