code: public static int reserveAndWriteUtf8(ByteBuf buf, CharSequence seq, int reserveBytes) {
          for (;;) {
              if (buf instanceof WrappedCompositeByteBuf) {
                  // WrappedCompositeByteBuf is a sub-class of AbstractByteBuf so it needs special handling.
                  buf = buf.unwrap();
              } else if (buf instanceof AbstractByteBuf) {
                  AbstractByteBuf byteBuf = (AbstractByteBuf) buf;
                  byteBuf.ensureWritable0(reserveBytes);
                  int written = writeUtf8(byteBuf, byteBuf.writerIndex, seq, seq.length());
                  byteBuf.writerIndex += written;
                  return written;
              } else if (buf instanceof WrappedByteBuf) {
                  // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
                  buf = buf.unwrap();
              } else {
                  byte[] bytes = seq.toString().getBytes(CharsetUtil.UTF_8);
                  buf.writeBytes(bytes);
                  return bytes.length;
              }
          }
      }
docs: Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write
  it into {@code reserveBytes} of a {@link ByteBuf}.
  <p>
  The {@code reserveBytes} must be computed (ie eagerly using {@link #utf8MaxBytes(CharSequence)}
  or exactly with {@link #utf8Bytes(CharSequence)}) to ensure this method to not fail: for performance reasons
  the index checks will be performed using just {@code reserveBytes}.<br>
  This method returns the actual number of bytes written.