Package io.netty.buffer

Examples of io.netty.buffer.CompositeByteBuf.addComponent()


            encoder.finish();

            ByteBuf msg;
            final CompositeByteBuf compressed = Unpooled.compositeBuffer();
            while ((msg = encoder.readOutbound()) != null) {
                compressed.addComponent(msg);
                compressed.writerIndex(compressed.writerIndex() + msg.readableBytes());
            }
            assertThat(compressed, is(notNullValue()));

            final byte[] compressedArray = new byte[compressed.readableBytes()];
View Full Code Here


            decoder.writeInbound(in);

            assertFalse(compressed.isReadable());
            final CompositeByteBuf decompressed = Unpooled.compositeBuffer();
            while ((msg = decoder.readInbound()) != null) {
                decompressed.addComponent(msg);
                decompressed.writerIndex(decompressed.writerIndex() + msg.readableBytes());
            }
            assertEquals(original, decompressed);

            compressed.release();
View Full Code Here

    private static byte[] uncompress(EmbeddedChannel channel, int length) throws Exception {
        CompositeByteBuf out = Unpooled.compositeBuffer();
        ByteBuf msg;
        while ((msg = channel.readOutbound()) != null) {
            out.addComponent(msg);
            out.writerIndex(out.writerIndex() + msg.readableBytes());
        }

        InputStream is = new ByteBufInputStream(out);
        LzmaInputStream lzmaIs = new LzmaInputStream(is, new Decoder());
View Full Code Here

     */
    private ChannelFuture continueHeaders(ChannelHandlerContext ctx, ChannelPromise promise,
            int streamId, int padding, ByteBuf headerBlock, ByteBuf firstFrame) {
        // Create a composite buffer wrapping the first frame and any continuation frames.
        CompositeByteBuf out = ctx.alloc().compositeBuffer();
        out.addComponent(firstFrame);
        int numBytes = firstFrame.readableBytes();

        // Process any continuation frames there might be.
        while (headerBlock.isReadable()) {
            ByteBuf frame = createContinuationFrame(ctx, streamId, headerBlock, padding);
View Full Code Here

        int numBytes = firstFrame.readableBytes();

        // Process any continuation frames there might be.
        while (headerBlock.isReadable()) {
            ByteBuf frame = createContinuationFrame(ctx, streamId, headerBlock, padding);
            out.addComponent(frame);
            numBytes += frame.readableBytes();
        }

        out.writerIndex(numBytes);
        return ctx.write(out, promise);
View Full Code Here

                int size = buf.readableBytes() - split;
                int oldIndex = buf.writerIndex();
                buf.writerIndex(split);
                ByteBuf buf2 = Unpooled.buffer(size).writeBytes(buf, split, oldIndex - split);
                CompositeByteBuf comp = Unpooled.compositeBuffer();
                comp.addComponent(buf).addComponent(buf2).writerIndex(length);
                cc.write(comp);
            } else {
                cc.write(buf);
            }
            i += length;
View Full Code Here

        ChannelOutboundBuffer buffer = new ChannelOutboundBuffer(channel);

        CompositeByteBuf comp = compositeBuffer(256);
        ByteBuf buf = directBuffer().writeBytes("buf1".getBytes(CharsetUtil.US_ASCII));
        for (int i = 0; i < 65; i++) {
            comp.addComponent(buf.copy()).writerIndex(comp.writerIndex() + buf.readableBytes());
        }
        buffer.addMessage(comp, comp.readableBytes(), channel.voidPromise());

        assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
        buffer.addFlush();
View Full Code Here

        run();
    }

    public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
        CompositeByteBuf buf = Unpooled.compositeBuffer();
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
        buf.writerIndex(4);
        testSimpleSend0(sb, cb, buf, true, BYTES, 1);

        CompositeByteBuf buf2 = Unpooled.compositeBuffer();
View Full Code Here

    }

    public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
        CompositeByteBuf buf = Unpooled.compositeBuffer();
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
        buf.writerIndex(4);
        testSimpleSend0(sb, cb, buf, true, BYTES, 1);

        CompositeByteBuf buf2 = Unpooled.compositeBuffer();
        buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
View Full Code Here

        buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
        buf.writerIndex(4);
        testSimpleSend0(sb, cb, buf, true, BYTES, 1);

        CompositeByteBuf buf2 = Unpooled.compositeBuffer();
        buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
        buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
        buf2.writerIndex(4);
        testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.