code: public static ByteBuffer cloneByteBuffer(ByteBuffer buf) {
      ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position());
      if (buf.hasArray()) {
        ret.put(buf.array(), buf.position(), buf.limit() - buf.position());
      } else {
        // direct buffer
        ret.put(buf);
      }
      ret.flip();
      return ret;
    }
docs: Clones a {@link ByteBuffer}.
  <p>
  The new bytebuffer will have the same content, but the type of the bytebuffer may not be the
  same.
  
  @param buf The ByteBuffer to copy
  @return The new ByteBuffer