Skip to content

Commit

Permalink
Ensure we always encode all data in JdkZlibEncoder. (netty#8305)
Browse files Browse the repository at this point in the history
Motivation:

In theory our estimation of the needed buffer could be off and so we need to ensure we grow it if there is no space left.

Modifications:

Ensure we grow the buffer if there is no space left in there but we still have data to deflate.

Result:

Correctly deflate data in all cases.
  • Loading branch information
normanmaurer authored Sep 22, 2018
1 parent a80c498 commit 9a3be34
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,18 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf uncompressed, ByteBuf o
}

deflater.setInput(inAry, offset, len);
while (!deflater.needsInput()) {
for (;;) {
deflate(out);
if (deflater.needsInput()) {
// Consumed everything
break;
} else {
if (!out.isWritable()) {
// We did not consume everything but the buffer is not writable anymore. Increase the capacity to
// make more room.
out.ensureWritable(out.writerIndex());
}
}
}
}

Expand Down

0 comments on commit 9a3be34

Please sign in to comment.