ChannelBuffer encoded = channel.getConfig().getBufferFactory() .getBuffer(data.order(), data.readableBytes() + 2); encoded.writeByte((byte) 0x00); encoded.writeBytes(data, data.readerIndex(), data.readableBytes()); encoded.writeByte((byte) 0xFF); ChannelBuffer encoded = channel.getConfig().getBufferFactory().getBuffer(data.order(), 2); encoded.writeByte((byte) 0xFF); encoded.writeByte((byte) 0x00); int dataLen = data.readableBytes(); ChannelBuffer encoded = channel.getConfig().getBufferFactory().getBuffer(data.order(), dataLen + 5);
/** * Creates a new embedder whose pipeline is composed of the specified * handlers. * * @param bufferFactory the {@link ChannelBufferFactory} to be used when * creating a new buffer. */ protected AbstractCodecEmbedder(ChannelBufferFactory bufferFactory, ChannelHandler... handlers) { this(handlers); getChannel().getConfig().setBufferFactory(bufferFactory); }
boolean success = false; try { ch.getConfig().setOptions(getOptions()); success = true; } finally { if (!success) { ch.close(); ch.bind(localAddress);
evt.getChannel().getConfig().setPipelineFactory(getPipelineFactory()); evt.getChannel().getConfig().setOptions(parentOptions); } finally { ctx.sendUpstream(evt); evt.getChannel().bind(localAddress).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) {
byte[] in = new byte[compressed.readableBytes()]; compressed.readBytes(in); z.next_in = in; z.next_in_index = 0; ChannelBuffer decompressed = ChannelBuffers.dynamicBuffer( compressed.order(), out.length, ctx.getChannel().getConfig().getBufferFactory()); z.next_out = out; z.next_out_index = 0;
ChannelBuffer header = dynamicBuffer( channel.getConfig().getBufferFactory()); encodeInitialLine(header, m); encodeHeaders(header, m); header.writeByte(CR); header.writeByte(LF); if (!content.readable()) { return header; // no content } else if (contentMustBeEmpty) { "if Transfer-Encoding is chunked."); } else { return wrappedBuffer(header, content); transferEncodingChunked = false; if (chunk instanceof HttpChunkTrailer) { ChannelBuffer trailer = dynamicBuffer( channel.getConfig().getBufferFactory()); trailer.writeByte((byte) '0'); trailer.writeByte(CR);
private ChannelBuffer buffer(ChannelHandlerContext ctx) throws Exception { ChannelBuffer buf = buffer.get(); if (buf == null) { ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory(); buf = ChannelBuffers.dynamicBuffer(factory); if (buffer.compareAndSet(null, buf)) { boolean success = false; try { oout = newObjectOutputStream(new ChannelBufferOutputStream(buf)); success = true; } finally { if (!success) { oout = null; } } } else { buf = buffer.get(); } } return buf; } }
private ChannelFuture finishEncode(final ChannelHandlerContext ctx, final ChannelEvent evt) { ChannelFuture future = Channels.succeededFuture(ctx.getChannel()); ctx.sendDownstream(evt); final ChannelBuffer footer = ChannelBuffers.dynamicBuffer(ctx.getChannel().getConfig().getBufferFactory()); final boolean gzip = isGzip(); synchronized (deflater) { footer.writeBytes(gzipHeader); int crcValue = (int) crc.getValue(); int uncBytes = deflater.getTotalIn(); footer.writeByte(crcValue); footer.writeByte(crcValue >>> 8); footer.writeByte(crcValue >>> 16); footer.writeByte(crcValue >>> 24); if (footer.readable()) { future = Channels.future(ctx.getChannel()); Channels.write(ctx, future, footer);
ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer(body.order(), lengthFieldLength); body.readableBytes() + lengthFieldLength : body.readableBytes(); switch (lengthFieldLength) { case 1: throw new Error("should not reach here"); return wrappedBuffer(header, body);
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer) || finished.get()) { return msg; } final ChannelBuffer uncompressed = (ChannelBuffer) msg; final int uncompressedLen = uncompressed.readableBytes(); if (uncompressedLen == 0) { return uncompressed; } final byte[] in = new byte[uncompressedLen]; uncompressed.readBytes(in); final int sizeEstimate = estimateCompressedSize(uncompressedLen); final ChannelBuffer compressed = ChannelBuffers.dynamicBuffer(sizeEstimate, channel.getConfig().getBufferFactory()); synchronized (deflater) { if (isGzip()) { crc.update(in); if (writeHeader) { compressed.writeBytes(gzipHeader); writeHeader = false; } } deflater.setInput(in); while (!deflater.needsInput()) { deflate(compressed); } } return compressed; }
final int uncompressedLen = uncompressed.readableBytes(); if (uncompressedLen == 0) { return uncompressed; uncompressed.readBytes(in); z.next_in = in; z.next_in_index = 0; result = ctx.getChannel().getConfig().getBufferFactory().getBuffer( uncompressed.order(), out, 0, z.next_out_index); } else { result = ChannelBuffers.EMPTY_BUFFER;
buffer.skipBytes(actualReadableBytes()); return null; byte b = buffer.readByte(); frameFinalFlag = (b & 0x80) != 0; frameRsv = (b & 0x70) >> 4; b = buffer.readByte(); boolean frameMasked = (b & 0x80) != 0; int framePayloadLen1 = b & 0x7F; payloadBuffer = buffer.readBytes(rbytes); if (framePayload == null) { framePayload = channel.getConfig().getBufferFactory().getBuffer(toFrameLength(framePayloadLength)); framePayload.writeBytes(payloadBuffer);
ChannelFuture future = future(ctx.getChannel()); write(ctx, future, httpResponse); return; ChannelAddress transportCandidate = (ChannelAddress) ctx.getChannel().getParent().getAttachment(); ChannelAddress candidate = new ChannelAddress(httpLocation, transportCandidate); ChannelFuture future = future(ctx.getChannel()); write(ctx, future, httpResponse); return; httpChildConfig.setStatus(HttpResponseStatus.OK); transport.getConfig().setBufferFactory(httpChildConfig.getBufferFactory()); this.httpChildChannel = httpChildChannel; contentLength -= content.readableBytes(); if (contentLength > 0) { httpChildChannel.readState(HttpReadState.CONTENT_CHUNKED); fireChannelConnected(httpChildChannel, httpRemoteAddress); if (content.readable()) { fireMessageReceived(httpChildChannel, content);
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory(); nettyOutAppBuf = factory.getBuffer(initialNettyOutAppBufCapacity); nettyOutAppBuf.writeBytes(outAppBuf); + " produced=" + result.bytesProduced() + " remaining=" + nioInNetBuf.remaining() + " data=" + ChannelBuffers.hexDump(ChannelBuffers.wrappedBuffer(nioInNetBuf))); if (nettyOutAppBuf != null && nettyOutAppBuf.readable()) { return nettyOutAppBuf; } else {
channel, pendingWrite.future, ChannelBuffers.EMPTY_BUFFER, channel.getRemoteAddress())); offered = true; } else { outNetBuf.flip(); int remaining = outNetBuf.remaining(); msg = ctx.getChannel().getConfig().getBufferFactory().getBuffer(remaining); msg.writeBytes(outNetBuf); outNetBuf.clear(); future = succeededFuture(channel); } else { future = pendingWrite.future; channel, future, msg, channel.getRemoteAddress()); offerEncryptedWriteRequest(encryptedWrite); offered = true;
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { ChannelBufferOutputStream bout = new ChannelBufferOutputStream(dynamicBuffer( estimatedLength, ctx.getChannel().getConfig().getBufferFactory())); bout.write(LENGTH_PLACEHOLDER); ObjectOutputStream oout = new CompactObjectOutputStream(bout); oout.writeObject(msg); oout.flush(); oout.close(); ChannelBuffer encoded = bout.buffer(); encoded.setInt(0, encoded.writerIndex() - 4); return encoded; } }
SpdyRstStreamFrame spdyRstStreamFrame = new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INVALID_STREAM); Channels.write(ctx, Channels.future(channel), spdyRstStreamFrame); return null; SpdyRstStreamFrame spdyRstStreamFrame = new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.PROTOCOL_ERROR); Channels.write(ctx, Channels.future(channel), spdyRstStreamFrame); return null; HttpHeaders.setContentLength(httpMessage, httpMessage.getContent().readableBytes()); removeMessage(streamId); return httpMessage; if (content.readableBytes() > maxContentLength - spdyDataFrame.getData().readableBytes()) { removeMessage(streamId); throw new TooLongFrameException( content = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory()); content.writeBytes(spdyDataFrame.getData()); httpMessage.setContent(content);
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { Channel transport = ctx.getChannel(); ChannelPipeline pipeline = ctx.getPipeline(); SslHandler handler = pipeline.get(SslHandler.class); SSLEngine tlsEngine = handler.getEngine(); ChannelAddress transportCandidate = (ChannelAddress) ctx.getChannel().getParent().getAttachment(); ChannelAddress candidate = new ChannelAddress(tlsLocation, transportCandidate); transport.close(); transport.getConfig().setBufferFactory(tlsChildConfig.getBufferFactory()); this.tlsChildChannel = tlsChildChannel; fireChannelOpen(tlsChildChannel); fireChannelBound(tlsChildChannel, tlsLocalAddress); fireChannelConnected(tlsChildChannel, tlsRemoteAddress);
/** * Reconnect to the remote address that the closed channel was connected to. * This creates a new {@link ChannelPipeline} with the same handler instances * contained in the old channel's pipeline. * * @param timeout Timer task handle. * * @throws Exception when reconnection fails. */ @Override public void run(Timeout timeout) throws Exception { ChannelPipeline old = channel.getPipeline(); CommandHandler<?, ?> handler = old.get(CommandHandler.class); RedisAsyncConnection<?, ?> connection = old.get(RedisAsyncConnection.class); ChannelPipeline pipeline = Channels.pipeline(this, handler, connection); Channel c = bootstrap.getFactory().newChannel(pipeline); c.getConfig().setOptions(bootstrap.getOptions()); c.connect((SocketAddress) bootstrap.getOption("remoteAddress")); } }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); ChannelBufferByteOutput output = new ChannelBufferByteOutput( ctx.getChannel().getConfig().getBufferFactory(), estimatedLength); output.getBuffer().writeBytes(LENGTH_PLACEHOLDER); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); ChannelBuffer encoded = output.getBuffer(); encoded.setInt(0, encoded.writerIndex() - 4); return encoded; }