Skip to content

Commit

Permalink
Issue #5198 - fix usage of inflater/deflater ByteBuffer API
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Sep 9, 2020
1 parent 2ed89cb commit 67e5ad3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ else if ((_flags & 0x2) == 0x2)

try
{
int pos = BufferUtil.flipToFill(buffer);
_inflater.inflate(buffer);
BufferUtil.flipToFlush(buffer, pos);
}
catch (DataFormatException x)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ public GzipBufferCB(ByteBuffer content, boolean complete, Callback callback)
super(callback);
_content = content;
_last = complete;
_crc.update(_content.slice());
_deflater.setInput(_content);
if (_last)
_deflater.finish();
}

@Override
Expand Down Expand Up @@ -320,29 +324,13 @@ protected Action process() throws Exception
// If the deflator is not finished, then compress more data
if (!_deflater.finished())
{
if (_deflater.needsInput())
{
// if there is no more content available to compress
// then we are either finished all content or just the current write.
if (BufferUtil.isEmpty(_content))
{
if (_last)
_deflater.finish();
else
return Action.SUCCEEDED;
}
else
{
// TODO: this might be a bad place to use ByteBuffer API, the CRC can copy the buffer anyway.
_crc.update(_content.slice());
_deflater.setInput(_content.slice());
if (_last)
_deflater.finish();
}
}
if (_deflater.needsInput() && !_last)
return Action.SUCCEEDED;

// deflate the content into the available space in the buffer
int pos = BufferUtil.flipToFill(_buffer);
_deflater.deflate(_buffer, _syncFlush ? Deflater.SYNC_FLUSH : Deflater.NO_FLUSH);
BufferUtil.flipToFlush(_buffer, pos);
}

// If we have finished deflation and there is room for the trailer.
Expand Down

0 comments on commit 67e5ad3

Please sign in to comment.