Skip to content

Commit 1e9fbbf

Browse files
committed
Reuse inflater/deflater
1 parent a566891 commit 1e9fbbf

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ We can check the getRemaining() method to see whether the data we supplied has b
166166
Note that this behavior doesn't occur if the message is "first compressed and then fragmented".
167167
*/
168168
if (inflater.getRemaining() > 0) {
169-
inflater = new Inflater(true);
169+
inflater.reset();
170170
decompress(inputFrame.getPayloadData().array(), output);
171171
}
172172

173173
if (inputFrame.isFin()) {
174174
decompress(TAIL_BYTES, output);
175175
// If context takeover is disabled, inflater can be reset.
176176
if (clientNoContextTakeover) {
177-
inflater = new Inflater(true);
177+
inflater.reset();
178178
}
179179
}
180180
} catch (DataFormatException e) {
@@ -244,8 +244,7 @@ public void encodeFrame(Framedata inputFrame) {
244244
}
245245

246246
if (serverNoContextTakeover) {
247-
deflater.end();
248-
deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
247+
deflater.reset();
249248
}
250249
}
251250

0 commit comments

Comments
 (0)