Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.array()


            return ((String) v).getBytes(charset);
        } else if (v != null) {
            final ByteBuf buf = Unpooled.copiedBuffer(v, charset);
            try {
                if (buf.hasArray()) {
                    return buf.array();
                } else {
                    byte[] result = new byte[buf.readableBytes()];
                    buf.readBytes(result);
                    return result;
                }
View Full Code Here


            long c = req.content().readLong();
            ByteBuf input = Unpooled.buffer(16);
            input.writeInt(a);
            input.writeInt(b);
            input.writeLong(c);
            res.content().writeBytes(WebSocketUtil.md5(input.array()));
        } else {
            // Old Hixie 75 handshake getMethod with no challenge:
            res.headers().add(HttpHeaderNames.WEBSOCKET_ORIGIN, req.headers().get(HttpHeaderNames.ORIGIN));
            res.headers().add(HttpHeaderNames.WEBSOCKET_LOCATION, uri());
            String protocol = req.headers().getAndConvert(HttpHeaderNames.WEBSOCKET_PROTOCOL);
View Full Code Here

    @Test
    public void testByteBufUtilsByteArrays()
    {
        ByteBuf buf = Unpooled.buffer(5, 5);
        ByteBufUtils.writeVarInt(buf, 1, 1);
        assertArrayEquals("1 as byte[] is [1]", new byte[] { 1, 0, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 127, 1);
        assertArrayEquals("127 as byte[] is [127]", new byte[] { 127, 0, 0, 0, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 1, 1);
        assertArrayEquals("1 as byte[] is [1]", new byte[] { 1, 0, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 127, 1);
        assertArrayEquals("127 as byte[] is [127]", new byte[] { 127, 0, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 128, 2);
        assertArrayEquals("128 as byte[] is [-128, 1]", new byte[] { -128, 1, 0, 0, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 127, 1);
        assertArrayEquals("127 as byte[] is [127]", new byte[] { 127, 0, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 128, 2);
        assertArrayEquals("128 as byte[] is [-128, 1]", new byte[] { -128, 1, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 16383, 2);
        assertArrayEquals("16383 as byte[] is [-1, 127]", new byte[] { -1, 127, 0, 0, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 128, 2);
        assertArrayEquals("128 as byte[] is [-128, 1]", new byte[] { -128, 1, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 16383, 2);
        assertArrayEquals("16383 as byte[] is [-1, 127]", new byte[] { -1, 127, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 16384, 3);
        assertArrayEquals("16384 as byte[] is [-1, -128, 1]", new byte[] { -128, -128, 1, 0, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 16383, 2);
        assertArrayEquals("16383 as byte[] is [-1, 127]", new byte[] { -1, 127, 0, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 16384, 3);
        assertArrayEquals("16384 as byte[] is [-1, -128, 1]", new byte[] { -128, -128, 1, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 2097151, 3);
        assertArrayEquals("2097151 as byte[] is [-1, -1, 127]", new byte[] { -1, -1, 127, 0, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 16384, 3);
        assertArrayEquals("16384 as byte[] is [-1, -128, 1]", new byte[] { -128, -128, 1, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 2097151, 3);
        assertArrayEquals("2097151 as byte[] is [-1, -1, 127]", new byte[] { -1, -1, 127, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 2097152, 4);
        assertArrayEquals("16384 as byte[] is [-128, -128, 1]", new byte[] { -128, -128, -128, 1, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 2097151, 3);
        assertArrayEquals("2097151 as byte[] is [-1, -1, 127]", new byte[] { -1, -1, 127, 0, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 2097152, 4);
        assertArrayEquals("16384 as byte[] is [-128, -128, 1]", new byte[] { -128, -128, -128, 1, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 268435455, 4);
        assertArrayEquals("268435455 as byte[] is [-1, -1, -1, 127]", new byte[] { -1, -1, -1, 127, 0 }, buf.array());
View Full Code Here

        ByteBufUtils.writeVarInt(buf, 2097152, 4);
        assertArrayEquals("16384 as byte[] is [-128, -128, 1]", new byte[] { -128, -128, -128, 1, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 268435455, 4);
        assertArrayEquals("268435455 as byte[] is [-1, -1, -1, 127]", new byte[] { -1, -1, -1, 127, 0 }, buf.array());

        buf.clear();
        ByteBufUtils.writeVarInt(buf, 268435456, 5);
        assertArrayEquals("268435456 as byte[] is [-1, -128, 1]", new byte[] { -128, -128, -128, -128, 1 }, buf.array());
    }
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.