Package io.netty.buffer

Examples of io.netty.buffer.CompositeByteBuf


        uncompressed.release();
        dataBuf.release();
    }

    private static ByteBuf readUncompressed(EmbeddedChannel channel) throws Exception {
        CompositeByteBuf uncompressed = Unpooled.compositeBuffer();
        ByteBuf msg;
        while ((msg = channel.readInbound()) != null) {
            uncompressed.addComponent(msg);
            uncompressed.writerIndex(uncompressed.writerIndex() + msg.readableBytes());
        }

        return uncompressed;
    }
View Full Code Here


        uncompressed.release();
        dataBuf.release();
    }

    private static ByteBuf readUncompressed(EmbeddedChannel channel) throws Exception {
        CompositeByteBuf uncompressed = Unpooled.compositeBuffer();
        ByteBuf msg;
        while ((msg = channel.readInbound()) != null) {
            uncompressed.addComponent(msg);
            uncompressed.writerIndex(uncompressed.writerIndex() + msg.readableBytes());
        }

        return uncompressed;
    }
View Full Code Here

            (byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
             0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
             0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
        });

        CompositeByteBuf actual = Unpooled.compositeBuffer();
        for (;;) {
            ByteBuf m = channel.readOutbound();
            if (m == null) {
                break;
            }
            actual.addComponent(m);
            actual.writerIndex(actual.writerIndex() + m.readableBytes());
        }
        assertEquals(releaseLater(expected), releaseLater(actual));
        in.release();
    }
View Full Code Here

        try {
            ByteBuf msg;

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

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

            compressed.release();
            decompressed.release();
            in.release();
        } finally {
            encoder.close();
            decoder.close();
View Full Code Here

        assertArrayEquals(data, uncompressed);
    }

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

        byte[] compressed = new byte[out.readableBytes()];
        out.readBytes(compressed);
        out.release();

        ByteArrayInputStream is = new ByteArrayInputStream(compressed);
        LZ4BlockInputStream lz4Is = new LZ4BlockInputStream(is);
        byte[] uncompressed = new byte[originalLength];
        int remaining = originalLength;
View Full Code Here

        assertArrayEquals(data, uncompressed);
    }

    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());
        }

        byte[] compressed = new byte[out.readableBytes()];
        out.readBytes(compressed);
        out.release();

        ByteArrayInputStream is = new ByteArrayInputStream(compressed);
        BZip2CompressorInputStream bZip2Is = new BZip2CompressorInputStream(is);
        byte[] uncompressed = new byte[length];
        int remaining = length;
View Full Code Here

        assertArrayEquals(data, uncompressed);
    }

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

        byte[] compressed = new byte[out.readableBytes()];
        out.readBytes(compressed);
        out.release();

        return LZFDecoder.decode(compressed);
    }
View Full Code Here

            ByteBuf in = Unpooled.wrappedBuffer(data, written, data.length - written);
            encoder.writeOutbound(in);
            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()];
            compressed.readBytes(compressedArray);
            written = 0;
            length = rand.nextInt(100);
            while (written + length < compressedArray.length) {
                in = Unpooled.wrappedBuffer(compressedArray, written, length);
                decoder.writeInbound(in);
                written += length;
                length = rand.nextInt(100);
            }
            in = Unpooled.wrappedBuffer(compressedArray, written, compressedArray.length - written);
            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();
            decompressed.release();
            original.release();
        } finally {
            encoder.close();
            decoder.close();
View Full Code Here

        assertArrayEquals(data, uncompressed);
    }

    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());
        byte[] uncompressed = new byte[length];
        int remaining = length;
        while (remaining > 0) {
            int read = lzmaIs.read(uncompressed, length - remaining, remaining);
            if (read > 0) {
                remaining -= read;
            } else {
                break;
            }
        }

        assertEquals(0, is.available());
        assertEquals(-1, is.read());
        assertEquals(-1, lzmaIs.read());

        is.close();
        lzmaIs.close();
        out.release();

        return uncompressed;
    }
View Full Code Here

     * number of CONTINUATION frames.
     */
    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);
            out.addComponent(frame);
            numBytes += frame.readableBytes();
        }

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

TOP

Related Classes of io.netty.buffer.CompositeByteBuf

Copyright © 2018 www.massapicom. 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.