/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
@Override public CompositeByteBuf call() { return Unpooled.compositeBuffer(); } },
/** * @param httpContent The http content to prefix * @return Produces HTTP content for {@code ]} */ public static HttpContent prefixComma(HttpContent httpContent) { CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer(2); compositeByteBuf.addComponent(true, Unpooled.wrappedBuffer(COMMA)); compositeByteBuf.addComponent(true, httpContent.content()); return httpContent.replace( compositeByteBuf ); } }
private byte[] fetchDecoderOutput() { final CompositeByteBuf decoded = Unpooled.compositeBuffer(); for (;;) { final ByteBuf buf = decoder.readInbound(); if (buf == null) { break; } if (!buf.isReadable()) { buf.release(); continue; } decoded.addComponent(true, buf); } final byte[] ret = ByteBufUtil.getBytes(decoded); decoded.release(); return ret; } }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (buffer != null) { long localsize = buffer.readableBytes(); checkSize(size + localsize); if (definedSize > 0 && definedSize < size + localsize) { throw new IOException("Out of size: " + (size + localsize) + " > " + definedSize); } size += localsize; if (byteBuf == null) { byteBuf = buffer; } else if (byteBuf instanceof CompositeByteBuf) { CompositeByteBuf cbb = (CompositeByteBuf) byteBuf; cbb.addComponent(true, buffer); } else { CompositeByteBuf cbb = compositeBuffer(Integer.MAX_VALUE); cbb.addComponents(true, byteBuf, buffer); byteBuf = cbb; } } if (last) { setCompleted(); } else { if (buffer == null) { throw new NullPointerException("buffer"); } } }
public ByteBuf toByteBuf() { return Unpooled.compositeBuffer().addComponents(value).writerIndex(size()).readerIndex(0); }
pending = (CompositeByteBuf) pendingChunks; } else { pending = Unpooled.compositeBuffer(); pending.addComponent(true, pendingChunks); pendingChunks = pending;
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
@Override public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) { Response response = (Response) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_RESPONSE); ProduceProcessor produceProcessor = (ProduceProcessor) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_PROCESSOR); Object body = response.getResult(); if (response.isFailed()) { body = ((InvocationException) body).getErrorData(); } if (Part.class.isInstance(body)) { return responseEx.sendPart((Part) body); } responseEx.setContentType(produceProcessor.getName() + "; charset=utf-8"); CompletableFuture<Void> future = new CompletableFuture<>(); try (BufferOutputStream output = new BufferOutputStream(Unpooled.compositeBuffer())) { produceProcessor.encodeResponse(output, body); responseEx.setBodyBuffer(output.getBuffer()); future.complete(null); } catch (Throwable e) { future.completeExceptionally(ExceptionFactory.convertProducerException(e)); } return future; } }
pending = (CompositeByteBuf) pendingChunks; } else { pending = Unpooled.compositeBuffer(); pending.addComponent(true, pendingChunks); pendingChunks = pending;
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
public void testSimpleSendCompositeHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { CompositeByteBuf buf = Unpooled.compositeBuffer(); buf.addComponent(true, Unpooled.buffer().writeBytes(BYTES, 0, 2)); buf.addComponent(true, Unpooled.buffer().writeBytes(BYTES, 2, 2)); testSimpleSend(sb, cb, buf, true, BYTES, 1); CompositeByteBuf buf2 = Unpooled.compositeBuffer(); buf2.addComponent(true, Unpooled.buffer().writeBytes(BYTES, 0, 2)); buf2.addComponent(true, Unpooled.buffer().writeBytes(BYTES, 2, 2)); testSimpleSend(sb, cb, buf2, true, BYTES, 4); }
public void testSimpleSendCompositeMixedByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { CompositeByteBuf buf = Unpooled.compositeBuffer(); buf.addComponent(true, Unpooled.directBuffer().writeBytes(BYTES, 0, 2)); buf.addComponent(true, Unpooled.buffer().writeBytes(BYTES, 2, 2)); testSimpleSend(sb, cb, buf, true, BYTES, 1); CompositeByteBuf buf2 = Unpooled.compositeBuffer(); buf2.addComponent(true, Unpooled.directBuffer().writeBytes(BYTES, 0, 2)); buf2.addComponent(true, Unpooled.buffer().writeBytes(BYTES, 2, 2)); testSimpleSend(sb, cb, buf2, true, BYTES, 4); }
public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { CompositeByteBuf buf = Unpooled.compositeBuffer(); buf.addComponent(true, Unpooled.directBuffer().writeBytes(BYTES, 0, 2)); buf.addComponent(true, Unpooled.directBuffer().writeBytes(BYTES, 2, 2)); testSimpleSend(sb, cb, buf, true, BYTES, 1); CompositeByteBuf buf2 = Unpooled.compositeBuffer(); buf2.addComponent(true, Unpooled.directBuffer().writeBytes(BYTES, 0, 2)); buf2.addComponent(true, Unpooled.directBuffer().writeBytes(BYTES, 2, 2)); testSimpleSend(sb, cb, buf2, true, BYTES, 4); }
@Test public void testCompositeByteBufBodySingleBuffer() throws Exception { ByteBuf header = Unpooled.copyLong(42); CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer(); compositeByteBuf.addComponent(true, header); assertEquals(1, compositeByteBuf.nioBufferCount()); testByteBufBody(compositeByteBuf); }
@Test public void testCompositeByteBufBodyMultipleBuffers() throws Exception { ByteBuf header = Unpooled.copyLong(42); CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer(); compositeByteBuf.addComponent(true, header.retainedSlice(0, 4)); compositeByteBuf.addComponent(true, header.slice(4, 4)); assertEquals(2, compositeByteBuf.nioBufferCount()); testByteBufBody(compositeByteBuf); }