BytesUtil { public static byte[] readBytesFromByteBufferWithoutConsume(ByteBuffer byteBuffer) { byte[] buffer = new byte[byteBuffer.remaining()]; byteBuffer.duplicate().get(buffer); return buffer; }  static byte[] readBytesFromByteBufferWithoutConsume(ByteBuffer byteBuffer); static byte[] readBytesFromByteBuffer(ByteBuffer byteBuffer);  }
@Test public void testReadBytesFromByteBufferWithoutConsume() { byte[] expectedBytes = "hello world".getBytes(); ByteBuffer bb = ByteBuffer.wrap(expectedBytes); byte[] returnedBytes = BytesUtil.readBytesFromByteBufferWithoutConsume(bb); assertArrayEquals(expectedBytes, returnedBytes); assertEquals(0, bb.position()); }