Package io.netty.buffer

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


            buf.writeByte(i);
        }
        ByteBuf input = buf.duplicate();

        EmbeddedChannel channel = new EmbeddedChannel(new FrameChunkDecoder(3));
        Assert.assertTrue(channel.writeInbound(input.readBytes(2)));
        try {
            channel.writeInbound(input.readBytes(4));
            Assert.fail();
        } catch (TooLongFrameException e) {
            // expected
View Full Code Here


        ByteBuf input = buf.duplicate();

        EmbeddedChannel channel = new EmbeddedChannel(new FrameChunkDecoder(3));
        Assert.assertTrue(channel.writeInbound(input.readBytes(2)));
        try {
            channel.writeInbound(input.readBytes(4));
            Assert.fail();
        } catch (TooLongFrameException e) {
            // expected
        }
        Assert.assertTrue(channel.writeInbound(input.readBytes(3)));
View Full Code Here

            channel.writeInbound(input.readBytes(4));
            Assert.fail();
        } catch (TooLongFrameException e) {
            // expected
        }
        Assert.assertTrue(channel.writeInbound(input.readBytes(3)));


        Assert.assertTrue(channel.finish());
        Assert.assertEquals(buf.readBytes(2), channel.readInbound());
        Assert.assertEquals(buf.skipBytes(4).readBytes(3), channel.readInbound());
View Full Code Here

        Assert.assertEquals(request.cas(), encoded.readLong());
        Assert.assertEquals(request.flags(), encoded.readInt());
        Assert.assertEquals(request.expires(), encoded.readInt());

        byte[] data = new byte[encoded.readableBytes()];
        encoded.readBytes(data);
        Assert.assertArrayEquals((request.key() + request.body()).getBytes(CharsetUtil.UTF_8), data);
        Assert.assertFalse(encoded.isReadable());

        Assert.assertFalse(channel.finish());
        Assert.assertNull(channel.readInbound());
View Full Code Here

            if (!buf.isReadable()) {
                return null;
            }
            buf.resetReaderIndex();
            byte[] b = new byte[getContent().readableBytes()];
            buf.readBytes(b);
            buf.resetReaderIndex();
            return new String(b, "UTF-8");
        }

        public String content() throws UnsupportedEncodingException, InterruptedException {
View Full Code Here

            ByteBuf buf = getContent();
            assertTrue("Content not readable", buf.isReadable());
            getContent().resetReaderIndex();
            if (type == byte[].class) {
                byte[] b = new byte[buf.readableBytes()];
                buf.readBytes(b);
                return type.cast(b);
            } else if (type == ByteBuf.class) {
                return type.cast(buf);
            } else if (type == String.class || type == CharSequence.class) {
                byte[] b = new byte[buf.readableBytes()];
View Full Code Here

                return type.cast(b);
            } else if (type == ByteBuf.class) {
                return type.cast(buf);
            } else if (type == String.class || type == CharSequence.class) {
                byte[] b = new byte[buf.readableBytes()];
                buf.readBytes(b);
                return type.cast(new String(b, "UTF-8"));
            } else {
                ObjectMapper m = new ObjectMapper();
                try {
                    return m.readValue(new ByteBufInputStream(buf), type);
View Full Code Here

    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    byte [] bytes = new byte [data.readableBytes()];
    data.readBytes(bytes);

    return new PacketRPCPipe(bytes);
  }

  private static PacketRPC createPacket(Object object, String method, Object... actuals) {
View Full Code Here

      tmpState.writeByte(stateWithId.stateId);
      stateWithId.state.writeData(tmpState);
    }

    data.writeShort((short) tmpState.readableBytes());
    data.writeBytes(tmpState.readBytes(tmpState.readableBytes()));
  }

  @Override
  public void readData(ByteBuf data) {
    super.readData(data);
View Full Code Here

   
    byte[] fileContent = readFromFile(256);
    ByteBuf buf = Unpooled.copiedBuffer(fileContent);
   
    byte[] byteArray = new byte[256];
    buf.readBytes(byteArray);
   
    for (int i = 0, b = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++, b++)
    {
      Assert.assertTrue(b == byteArray[i]);
    }
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.