DeflateFrameExtension extends CompressExtension { @Override public void incomingFrame(Frame frame) { if (frame.getType().isControl() || !frame.isRsv1() || !frame.hasPayload()) { nextIncomingFrame(frame); return; } try { ByteAccumulator accumulator = newByteAccumulator(); decompress(accumulator, frame.getPayload()); decompress(accumulator, TAIL_BYTES_BUF.slice()); forwardIncoming(frame, accumulator); } catch (DataFormatException e) { throw new BadPayloadException(e); } }  @Override String getName(); @Override void incomingFrame(Frame frame);  }
@Test public void testCompressAndDecompressBigPayload() throws Exception { byte[] input = new byte[1024 * 1024]; new Random().nextBytes(input); int maxMessageSize = (1024 * 1024) + 8192; DeflateFrameExtension clientExtension = new DeflateFrameExtension(); clientExtension.setPolicy(WebSocketPolicy.newClientPolicy()); clientExtension.getPolicy().setMaxBinaryMessageSize(maxMessageSize); clientExtension.getPolicy().setMaxBinaryMessageBufferSize(maxMessageSize); clientExtension.setConfig(ExtensionConfig.parse("deflate-frame")); final DeflateFrameExtension serverExtension = new DeflateFrameExtension(); serverExtension.setPolicy(WebSocketPolicy.newServerPolicy()); serverExtension.getPolicy().setMaxBinaryMessageSize(maxMessageSize); serverExtension.getPolicy().setMaxBinaryMessageBufferSize(maxMessageSize); serverExtension.setConfig(ExtensionConfig.parse("deflate-frame")); clientExtension.setNextOutgoingFrames(new OutgoingFrames() { @Override public void outgoingFrame(Frame frame, Consumer<Result<Void>> result) { LOG.debug("outgoingFrame({})", frame); serverExtension.incomingFrame(frame); result.accept(Result.SUCCESS); } }); final ByteArrayOutputStream result = new ByteArrayOutputStream(input.length); serverExtension.setNextIncomingFrames(new IncomingFrames() { @Override public void incomingFrame(Frame frame) { LOG.debug("incomingFrame({})", frame); try { result.write(BufferUtils.toArray(frame.getPayload())); } catch (IOException x) { throw new RuntimeException(x); } } }); BinaryFrame frame = new BinaryFrame(); frame.setPayload(input); frame.setFin(true); clientExtension.outgoingFrame(frame, null); assertArrayEquals(input, result.toByteArray()); }