code: public static ByteBuffer copyOf(ByteBuffer buffer) {
          final int n = buffer.capacity();
          final ByteBuffer buffer2 = ByteBuffer.allocate(n);
          final int p = buffer.position();
          buffer.position(0);
          final int l = buffer.limit();
          buffer.limit(n);
          buffer2.put(buffer);
          buffer2.flip();
          buffer.position(p);
          buffer.limit(l);
          return buffer2;
      }
docs: Returns a newly-allocated copy of a given {@link ByteBuffer}'s {@link ByteBuffer#remaining() remaining} contents. <br>
  Upon return from this method, the original buffer's {@link ByteBuffer#position() position} will be unchanged, and the
  returned buffer's position will be 0.
  <p>
  This method is not thread-safe.
  
  @param buffer The buffer to copy.
  @return A copy of the buffer's {@link ByteBuffer#remaining() remaining} contents.