// Test for https://github.com/netty/netty/issues/1060
 @Test
 public void testReadWithEmptyCompositeBuffer() {
   ByteBuf buf = freeLater(compositeBuffer());
   int n = 65;
   for (int i = 0; i < n; i++) {
     buf.writeByte(1);
     assertEquals(1, buf.readByte());
   }
 }
  @Test
  public void testGetReadByte() {
    ByteBuf buf =
        buffer(
            ((ByteBuffer) allocate(2).put(new byte[] {(byte) 1, (byte) 2}).flip())
                .asReadOnlyBuffer());
    Assert.assertEquals(1, buf.getByte(0));
    Assert.assertEquals(2, buf.getByte(1));

    Assert.assertEquals(1, buf.readByte());
    Assert.assertEquals(2, buf.readByte());
    Assert.assertFalse(buf.isReadable());
  }
Пример #3
0
  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) { // (2)
    ByteBuf in = (ByteBuf) msg;
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      while (in.isReadable()) { // (1)
        byte readByte = in.readByte();
        baos.write(readByte);
        // System.out.flush();

        ctx.flush();
      }
      System.out.println("Msg Read: " + baos.toString());
    } finally {
      // System.out.println("finish!");
      ReferenceCountUtil.release(msg); // (2)
    }
  }
Пример #4
0
 @Override
 public byte readByte() {
   return buf.readByte();
 }