@Override public Future<Void> sendContinuationFrame(String payload, boolean finalFragment, int rsv) { return channel.writeAndFlush(new ContinuationWebSocketFrame(finalFragment, rsv, payload)); }
@Override public Future<Void> sendContinuationFrame(ByteBuf payload, boolean finalFragment, int rsv) { return channel.writeAndFlush(new ContinuationWebSocketFrame(finalFragment, rsv, payload)); }
@Override public ContinuationWebSocketFrame replace(ByteBuf content) { return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); }
/** * Fetches a chunked data from the stream. Once this method returns the last chunk * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()} * call must return {@code true}. * * @param allocator {@link ByteBufAllocator} * @return {@link WebSocketFrame} contain chunk of data */ @Override public WebSocketFrame readChunk(ByteBufAllocator allocator) throws Exception { ByteBuf buf = input.readChunk(allocator); if (buf == null) { return null; } return new ContinuationWebSocketFrame(input.isEndOfInput(), rsv, buf); }
@Override protected void encode(ChannelHandlerContext ctx, WebSocketConvertHandler.MyWebSocketFrame msg, List<Object> out) throws Exception { ByteBuf payload = msg.getData().duplicate().retain(); switch (msg.getType()) { case BINARY: out.add(new BinaryWebSocketFrame(payload)); break; case TEXT: out.add(new TextWebSocketFrame(payload)); break; case CLOSE: out.add(new CloseWebSocketFrame(true, 0, payload)); break; case CONTINUATION: out.add(new ContinuationWebSocketFrame(payload)); break; case PONG: out.add(new PongWebSocketFrame(payload)); break; case PING: out.add(new PingWebSocketFrame(payload)); break; default: throw new IllegalStateException( "Unsupported websocket msg " + msg);} }
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
outMsg = new BinaryWebSocketFrame(msg.isFinalFragment(), newRsv(msg), compositeUncompressedContent); } else if (msg instanceof ContinuationWebSocketFrame) { outMsg = new ContinuationWebSocketFrame(msg.isFinalFragment(), newRsv(msg), compositeUncompressedContent); } else {
return; } else if (frameOpcode == OPCODE_CONT) { out.add(new ContinuationWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null;
outMsg = new BinaryWebSocketFrame(msg.isFinalFragment(), rsv(msg), compressedContent); } else if (msg instanceof ContinuationWebSocketFrame) { outMsg = new ContinuationWebSocketFrame(msg.isFinalFragment(), rsv(msg), compressedContent); } else { throw new CodecException("unexpected frame type: " + msg.getClass().getName());
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
@Override public ChannelFuture pushText(String text, boolean finalFrame) { if (continuationFrameType == WebSocketFrameType.BINARY) { throw new IllegalStateException("Cannot interrupt WebSocket binary frame continuation"); } if (closeFrameSent) { throw new IllegalStateException("Close frame already sent. Cannot push text data!"); } if (continuationFrameType != null) { if (finalFrame) { continuationFrameType = null; } return ctx.writeAndFlush(new ContinuationWebSocketFrame(finalFrame, 0, text)); } if (!finalFrame) { continuationFrameType = WebSocketFrameType.TEXT; } return ctx.writeAndFlush(new TextWebSocketFrame(finalFrame, 0, text)); }
@Override public ContinuationWebSocketFrame replace(ByteBuf content) { return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); }
@Override public ContinuationWebSocketFrame replace(ByteBuf content) { return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); }
@Override public ContinuationWebSocketFrame replace(ByteBuf content) { return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); }
@Override public ContinuationWebSocketFrame replace(ByteBuf content) { return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); }
@Override public ChannelFuture pushBinary(ByteBuffer data, boolean finalFrame) { if (continuationFrameType == WebSocketFrameType.TEXT) { throw new IllegalStateException("Cannot interrupt WebSocket text frame continuation"); } if (closeFrameSent) { throw new IllegalStateException("Close frame already sent. Cannot push binary data."); } if (continuationFrameType != null) { if (finalFrame) { continuationFrameType = null; } return ctx.writeAndFlush(new ContinuationWebSocketFrame(finalFrame, 0, getNettyByteBuf(data))); } if (!finalFrame) { continuationFrameType = WebSocketFrameType.BINARY; } return ctx.writeAndFlush(new BinaryWebSocketFrame(finalFrame, 0, getNettyByteBuf(data))); }
/** * Fetches a chunked data from the stream. Once this method returns the last chunk * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()} * call must return {@code true}. * * @param allocator {@link ByteBufAllocator} * @return {@link WebSocketFrame} contain chunk of data */ @Override public WebSocketFrame readChunk(ByteBufAllocator allocator) throws Exception { ByteBuf buf = input.readChunk(allocator); if (buf == null) { return null; } return new ContinuationWebSocketFrame(input.isEndOfInput(), rsv, buf); }
/** * Fetches a chunked data from the stream. Once this method returns the last chunk * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()} * call must return {@code true}. * * @param allocator {@link ByteBufAllocator} * @return {@link WebSocketFrame} contain chunk of data */ @Override public WebSocketFrame readChunk(ByteBufAllocator allocator) throws Exception { ByteBuf buf = input.readChunk(allocator); if (buf == null) { return null; } return new ContinuationWebSocketFrame(input.isEndOfInput(), rsv, buf); }
/** * Fetches a chunked data from the stream. Once this method returns the last chunk * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()} * call must return {@code true}. * * @param allocator {@link ByteBufAllocator} * @return {@link WebSocketFrame} contain chunk of data */ @Override public WebSocketFrame readChunk(ByteBufAllocator allocator) throws Exception { ByteBuf buf = input.readChunk(allocator); if (buf == null) { return null; } return new ContinuationWebSocketFrame(input.isEndOfInput(), rsv, buf); }
/** * Fetches a chunked data from the stream. Once this method returns the last chunk * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()} * call must return {@code true}. * * @param allocator {@link ByteBufAllocator} * @return {@link WebSocketFrame} contain chunk of data */ @Override public WebSocketFrame readChunk(ByteBufAllocator allocator) throws Exception { ByteBuf buf = input.readChunk(allocator); if (buf == null) { return null; } return new ContinuationWebSocketFrame(input.isEndOfInput(), rsv, buf); }