/** * {@inheritDoc} * <p>This implementation uses Netty's {@link CompositeByteBuf}. */ @Override public DataBuffer join(List<? extends DataBuffer> dataBuffers) { Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty"); int bufferCount = dataBuffers.size(); if (bufferCount == 1) { return dataBuffers.get(0); } CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount); for (DataBuffer dataBuffer : dataBuffers) { Assert.isInstanceOf(NettyDataBuffer.class, dataBuffer); composite.addComponent(true, ((NettyDataBuffer) dataBuffer).getNativeBuffer()); } return new NettyDataBuffer(composite, this); }
@Override public void channelReadComplete(final ChannelHandlerContext ctx) throws Exception { if (bufs.numComponents() > 0) { ctx.fireChannelRead(bufs); bufs = ByteBufAllocator.DEFAULT.compositeBuffer(); } ctx.fireChannelReadComplete(); } }
/** * {@inheritDoc} * <p>This implementation uses Netty's {@link CompositeByteBuf}. */ @Override public DataBuffer join(List<? extends DataBuffer> dataBuffers) { Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty"); int bufferCount = dataBuffers.size(); if (bufferCount == 1) { return dataBuffers.get(0); } CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount); for (DataBuffer dataBuffer : dataBuffers) { Assert.isInstanceOf(NettyDataBuffer.class, dataBuffer); composite.addComponent(true, ((NettyDataBuffer) dataBuffer).getNativeBuffer()); } return new NettyDataBuffer(composite, this); }
composite = (CompositeByteBuf) cumulation; } else { composite = alloc.compositeBuffer(Integer.MAX_VALUE); composite.addComponent(true, cumulation);
public ByteBuf serializeRequest(I message) throws IOException { switch (requestType) { case PROTOBUF: return serializeProto((Message) message); default: final CompositeByteBuf out = alloc.compositeBuffer(); try (ByteBufOutputStream os = new ByteBufOutputStream(out)) { ByteStreams.copy(method.streamRequest(message), os); } return out; } }
public ByteBuf serializeResponse(O message) throws IOException { switch (responseType) { case PROTOBUF: return serializeProto((Message) message); default: final CompositeByteBuf out = alloc.compositeBuffer(); try (ByteBufOutputStream os = new ByteBufOutputStream(out)) { ByteStreams.copy(method.streamResponse(message), os); } return out; } }
private ByteBuf writeCompressed(ByteBuf message) throws IOException { final CompositeByteBuf compressed = alloc.compositeBuffer(); try (OutputStream compressingStream = compressor.compress(new ByteBufOutputStream(compressed))) { compressingStream.write(ByteBufUtil.getBytes(message)); } finally { message.release(); } return write(compressed, true); }
final CompositeByteBuf cbb = ctx.alloc().compositeBuffer(numChunks);
composite = (CompositeByteBuf) cumulation; } else { composite = alloc.compositeBuffer(Integer.MAX_VALUE); composite.addComponent(true, cumulation);
@Override public ByteBuf cumulate(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf in) { ByteBuf buffer; if (cumulation.refCnt() > 1) { // Expand cumulation (by replace it) when the refCnt is greater then 1 which may happen when the user // use slice().retain() or duplicate().retain(). // // See: // - https://github.com/netty/netty/issues/2327 // - https://github.com/netty/netty/issues/1764 buffer = expandCumulation(alloc, cumulation, in.readableBytes()); buffer.writeBytes(in); in.release(); } else { CompositeByteBuf composite; if (cumulation instanceof CompositeByteBuf) { composite = (CompositeByteBuf) cumulation; } else { composite = alloc.compositeBuffer(Integer.MAX_VALUE); composite.addComponent(true, cumulation); } composite.addComponent(true, in); buffer = composite; } return buffer; } };
} else if (!receivedContent.isEmpty()) { int size = receivedContent.size(); CompositeByteBuf byteBufs = channelHandlerContext.alloc().compositeBuffer(size); for (ByteBufHolder holder : receivedContent) { ByteBuf content = holder.content();
/** * Compose {@code cumulation} and {@code next} into a new {@link CompositeByteBuf}. */ protected final ByteBuf composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) { // Create a composite buffer to accumulate this pair and potentially all the buffers // in the queue. Using +2 as we have already dequeued current and next. CompositeByteBuf composite = alloc.compositeBuffer(size() + 2); try { composite.addComponent(true, cumulation); composite.addComponent(true, next); } catch (Throwable cause) { composite.release(); safeRelease(next); throwException(cause); } return composite; }
/** * @param byteBufs The {@link ByteBuf}s * @return The {@link ByteBuffer} */ public ByteBuffer write(ByteBuf... byteBufs) { if (this.delegate instanceof CompositeByteBuf) { CompositeByteBuf compositeByteBuf = (CompositeByteBuf) this.delegate; compositeByteBuf.addComponents(true, byteBufs); } else { ByteBuf current = this.delegate; CompositeByteBuf composite = current.alloc().compositeBuffer(byteBufs.length + 1); this.delegate = composite; composite.addComponent(true, current); composite.addComponents(true, byteBufs); } return this; }
.readableBytes(); composite = alloc .compositeBuffer(); composite.addComponent( cumulation).writerIndex(
/** * Compose {@code cumulation} and {@code next} into a new {@link CompositeByteBuf}. */ protected final ByteBuf composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) { // Create a composite buffer to accumulate this pair and potentially all the buffers // in the queue. Using +2 as we have already dequeued current and next. CompositeByteBuf composite = alloc.compositeBuffer(size() + 2); try { composite.addComponent(true, cumulation); composite.addComponent(true, next); } catch (Throwable cause) { composite.release(); safeRelease(next); throwException(cause); } return composite; }
/** * Compose {@code cumulation} and {@code next} into a new {@link CompositeByteBuf}. */ protected final ByteBuf composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) { // Create a composite buffer to accumulate this pair and potentially all the buffers // in the queue. Using +2 as we have already dequeued current and next. CompositeByteBuf composite = alloc.compositeBuffer(size() + 2); try { composite.addComponent(true, cumulation); composite.addComponent(true, next); } catch (Throwable cause) { composite.release(); safeRelease(next); throwException(cause); } return composite; }
CompositeByteBuf compositeUncompressedContent = ctx.alloc().compositeBuffer(); for (;;) { ByteBuf partUncompressedContent = decoder.readInbound();
CompositeByteBuf content = ctx.alloc().compositeBuffer(maxCumulationBufferComponents); if (m instanceof ByteBufHolder) { appendPartialContent(content, ((ByteBufHolder) m).content());
CompositeByteBuf fullCompressedContent = ctx.alloc().compositeBuffer(); for (;;) { ByteBuf partCompressedContent = encoder.readOutbound();
CompositeByteBuf content = ctx.alloc().compositeBuffer(maxCumulationBufferComponents); if (m instanceof ByteBufHolder) { appendPartialContent(content, ((ByteBufHolder) m).content());