private void writeQuickFullUTF(String str, int strlen) throws IOException {
    int utfSizeIdx = buffer.position();
    // skip bytes reserved for length
    buffer.position(utfSizeIdx + 2);
    for (int i = 0; i < strlen; i++) {
      int c = str.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        buffer.put((byte) c);
      } else if (c > 0x07FF) {
        buffer.put((byte) (0xE0 | ((c >> 12) & 0x0F)));
        buffer.put((byte) (0x80 | ((c >> 6) & 0x3F)));
        buffer.put((byte) (0x80 | ((c) & 0x3F)));
      } else {
        buffer.put((byte) (0xC0 | ((c >> 6) & 0x1F)));
        buffer.put((byte) (0x80 | ((c) & 0x3F)));
      }
    }
    int utflen = buffer.position() - (utfSizeIdx + 2);
    if (utflen > 65535) {
      // act as if we wrote nothing to this buffer
      buffer.position(utfSizeIdx);
      throw new UTFDataFormatException();
    }
    buffer.putShort(utfSizeIdx, (short) utflen);
  }
Used when we know the max size will fit in the current buffer.
geode-core/src/main/java/org/apache/geode/internal/tcp/MsgStreamer.java