@Override public void write(ByteBuffer bb) { buf.ensureWritable(bb.remaining()); buf.writeBytes(bb); }
@Override public void write(byte[] b, int off, int len) { buf.ensureWritable(len); buf.writeBytes(b, off, len); }
private void writeResponse(ChannelHandlerContext ctx, byte[] response) { LOG.trace("Sending token size={} from initSASLContext.", response.length); ctx.writeAndFlush( ctx.alloc().buffer(4 + response.length).writeInt(response.length).writeBytes(response)); }
private void write(ChannelHandlerContext ctx, HttpResponseStatus status, Optional<String> content) { DefaultFullHttpResponse resp; if (content.isPresent()) { ByteBuf buf = ctx.alloc().buffer().writeBytes(Bytes.toBytes(content.get())); resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buf); resp.headers().set(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes()); } else { resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); } resp.headers().set(HttpHeaderNames.CONTENT_TYPE, "text-plain; charset=UTF-8"); ctx.writeAndFlush(resp); }
NettyRpcConnection(NettyRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; byte[] connectionHeaderPreamble = getConnectionHeaderPreamble(); this.connectionHeaderPreamble = Unpooled.directBuffer(connectionHeaderPreamble.length).writeBytes(connectionHeaderPreamble); ConnectionHeader header = getConnectionHeader(); this.connectionHeaderWithLength = Unpooled.directBuffer(4 + header.getSerializedSize()); this.connectionHeaderWithLength.writeInt(header.getSerializedSize()); header.writeTo(new ByteBufOutputStream(this.connectionHeaderWithLength)); }
@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (cBuf.isReadable()) { byte[] b = new byte[cBuf.readableBytes()]; cBuf.readBytes(b); cBuf.discardReadComponents(); byte[] wrapped = saslClient.wrap(b, 0, b.length); ByteBuf buf = ctx.alloc().ioBuffer(4 + wrapped.length); buf.writeInt(wrapped.length); buf.writeBytes(wrapped); ctx.write(buf); } ctx.flush(); }
private void writeResponse(ChannelHandlerContext ctx, byte[] response) { LOG.trace("Sending token size={} from initSASLContext.", response.length); ctx.writeAndFlush( ctx.alloc().buffer(4 + response.length).writeInt(response.length).writeBytes(response)); }
@Override public ByteBuf writeBytes(ByteBuffer src) { buf.writeBytes(src); return this; }
@Override public ByteBuf writeBytes(byte[] src, int srcIndex, int length) { buf.writeBytes(src, srcIndex, length); return this; }
@Override public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) { buf.writeBytes(src, srcIndex, length); return this; }
@Override public ByteBuf writeBytes(ByteBuf src) { buf.writeBytes(src); return this; }
@Override public ByteBuf writeBytes(ByteBuf src, int length) { buf.writeBytes(src, length); return this; }
@Override public ByteBuf writeBytes(ByteBuffer src) { buf.writeBytes(src); return this; }
NettyRpcConnection(NettyRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; byte[] connectionHeaderPreamble = getConnectionHeaderPreamble(); this.connectionHeaderPreamble = Unpooled.directBuffer(connectionHeaderPreamble.length).writeBytes(connectionHeaderPreamble); ConnectionHeader header = getConnectionHeader(); this.connectionHeaderWithLength = Unpooled.directBuffer(4 + header.getSerializedSize()); this.connectionHeaderWithLength.writeInt(header.getSerializedSize()); header.writeTo(new ByteBufOutputStream(this.connectionHeaderWithLength)); }
/** * Encode the key. * * @param buf the {@link ByteBuf} to write into. * @param key the key to encode. */ private static void encodeKey(ByteBuf buf, ByteBuf key) { if (key == null || !key.isReadable()) { return; } buf.writeBytes(key); }
void encode(ByteBuf buf) { if (bytes == null) { ByteBufUtil.copy(codeAsText, buf); buf.writeByte(SP); buf.writeCharSequence(reasonPhrase, CharsetUtil.US_ASCII); } else { buf.writeBytes(bytes); } } }
static ByteBuf expandCumulation(ByteBufAllocator alloc, ByteBuf cumulation, int readable) { ByteBuf oldCumulation = cumulation; cumulation = alloc.buffer(oldCumulation.readableBytes() + readable); cumulation.writeBytes(oldCumulation); oldCumulation.release(); return cumulation; }
public MqttPublishMessage build() { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, retained, 0); MqttPublishVariableHeader mqttVariableHeader = new MqttPublishVariableHeader(topic, messageId); return new MqttPublishMessage(mqttFixedHeader, mqttVariableHeader, Unpooled.buffer().writeBytes(payload)); } }
private void writeIntegerMessage(ByteBufAllocator allocator, IntegerRedisMessage msg, List<Object> out) { ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + RedisConstants.LONG_MAX_LENGTH + RedisConstants.EOL_LENGTH); buf.writeByte(RedisMessageType.INTEGER.value()); buf.writeBytes(numberToBytes(msg.value())); buf.writeShort(RedisConstants.EOL_SHORT); out.add(buf); }
@Override protected int doReadBytes(ByteBuf byteBuf) throws Exception { final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); allocHandle.attemptedBytesRead(byteBuf.writableBytes()); return byteBuf.writeBytes(javaChannel(), allocHandle.attemptedBytesRead()); }