code: public static ByteBuf copiedBuffer(ByteBuffer buffer) {
          int length = buffer.remaining();
          if (length == 0) {
              return EMPTY_BUFFER;
          }
          byte[] copy = PlatformDependent.allocateUninitializedArray(length);
          // Duplicate the buffer so we not adjust the position during our get operation.
          // See https://github.com/netty/netty/issues/3896
          ByteBuffer duplicate = buffer.duplicate();
          duplicate.get(copy);
          return wrappedBuffer(copy).order(duplicate.order());
      }
docs: Creates a new buffer whose content is a copy of the specified
  {@code buffer}'s current slice.  The new buffer's {@code readerIndex}
  and {@code writerIndex} are {@code 0} and {@code buffer.remaining}
  respectively.