NettyUtil { public static byte[] copy(ByteBuf buffer) { byte[] bytes = new byte[buffer.readableBytes()]; int readerIndex = buffer.readerIndex(); buffer.getBytes(readerIndex, bytes); return bytes; }  static byte[] copy(ByteBuf buffer);  }
@Test public void testCopy() throws Exception { String original = "TestString"; ByteBuf nettyBuf = Unpooled.copiedBuffer(original, CharsetUtil.UTF_8); byte[] byteArray = NettyUtil.copy(nettyBuf); String copied = new String(byteArray); Assert.assertThat(original, Matchers.equalTo(copied)); }