code: public static ByteBuf copiedBuffer(ByteBuf buffer) {
          int readable = buffer.readableBytes();
          if (readable > 0) {
              ByteBuf copy = buffer(readable);
              copy.writeBytes(buffer, buffer.readerIndex(), readable);
              return copy;
          } else {
              return EMPTY_BUFFER;
          }
      }
docs: Creates a new buffer whose content is a copy of the specified
  {@code buffer}'s readable bytes.  The new buffer's {@code readerIndex}
  and {@code writerIndex} are {@code 0} and {@code buffer.readableBytes}
  respectively.