Skip to content

Commit

Permalink
Issue #6050 - add comment and change variable name to clarify
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Mar 11, 2021
1 parent c8dd4cd commit 2f2b6ba
Showing 1 changed file with 10 additions and 8 deletions.
Expand Up @@ -197,14 +197,15 @@ protected void decompress(ByteAccumulator accumulator, ByteBuffer buf) throws Da

while (true)
{
// The buffer returned by the accumulator might not be empty, so we must append starting from the limit.
ByteBuffer buffer = accumulator.ensureBuffer(DECOMPRESS_BUF_SIZE);
int read = inflater.inflate(buffer.array(), buffer.arrayOffset() + buffer.limit(), buffer.capacity() - buffer.limit());
buffer.limit(buffer.limit() + read);
accumulator.addLength(read);
int written = inflater.inflate(buffer.array(), buffer.arrayOffset() + buffer.limit(), buffer.capacity() - buffer.limit());
buffer.limit(buffer.limit() + written);
accumulator.addLength(written);
if (LOG.isDebugEnabled())
LOG.debug("Decompressed {} bytes into buffer {} from {}", read, BufferUtil.toDetailString(buffer), toDetail(inflater));
LOG.debug("Decompressed {} bytes into buffer {} from {}", written, BufferUtil.toDetailString(buffer), toDetail(inflater));

if (read <= 0)
if (written <= 0)
break;
}
}
Expand Down Expand Up @@ -495,14 +496,15 @@ private void compress(FrameEntry entry, boolean first)
{
while (true)
{
// The buffer returned by the accumulator might not be empty, so we must append starting from the limit.
ByteBuffer buffer = accumulator.ensureBuffer(8, outputLength);
int compressed = deflater.deflate(buffer.array(), buffer.arrayOffset() + buffer.limit(), buffer.capacity() - buffer.limit(), Deflater.SYNC_FLUSH);
buffer.limit(buffer.limit() + compressed);
int written = deflater.deflate(buffer.array(), buffer.arrayOffset() + buffer.limit(), buffer.capacity() - buffer.limit(), Deflater.SYNC_FLUSH);
buffer.limit(buffer.limit() + written);

if (LOG.isDebugEnabled())
LOG.debug("Wrote {} bytes to output buffer", accumulator);

if (compressed <= 0)
if (written <= 0)
break;
}

Expand Down

0 comments on commit 2f2b6ba

Please sign in to comment.