code: public static byte[] newByteArrayFromByteBuffer(ByteBuffer buf) {
      final int length = buf.remaining();
      byte[] bytes = new byte[length];
      // transfer bytes from this buffer into the given destination array
      buf.duplicate().get(bytes, 0, length);
      return bytes;
    }
docs: Creates a byte array from the given ByteBuffer, the position property of input
  {@link ByteBuffer} remains unchanged.
  
  @param buf source ByteBuffer
  @return a newly created byte array