Skip to content

Commit

Permalink
Explicitly call Deflater/Inflater#close to free native resources (#203)…
Browse files Browse the repository at this point in the history
… (#204)
  • Loading branch information
mkr authored Aug 1, 2022
1 parent 8b3a416 commit 529b240
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ static byte[] writeToByteArrayOutputStream(Inflater inflater, ByteArrayOutputStr
* @throws IOException
*/
default byte[] compress(byte[] record) throws IOException {
return writeToDeflatorObject(record, getDeflatorObject(record));
Deflater deflator = getDeflatorObject(record);
byte[] compressed = writeToDeflatorObject(record, deflator);
deflator.end();
return compressed;
}

/**
Expand All @@ -95,6 +98,9 @@ default byte[] compress(byte[] record) throws IOException {
* @throws IOException
*/
default byte[] decompress(byte[] compressedRecord, int start, int end) throws IOException {
return decompress(getInflatorObject(compressedRecord, start, end), compressedRecord.length);
Inflater inflator = getInflatorObject(compressedRecord, start, end);
byte[] decompressed = decompress(inflator, compressedRecord.length);
inflator.end();
return decompressed;
}
}

0 comments on commit 529b240

Please sign in to comment.