code: public static void encode(byte[] dst, int offset, String s) {
          final int length = s.length();
          for (int i = 0; i < length; i++) {
              char ch = s.charAt(i);
              if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.
                  dst[offset++] = (byte) ch;
              } else if (ch <= 2047) {
                  dst[offset++] = (byte) (0xc0 | (0x1f & (ch >> 6)));
                  dst[offset++] = (byte) (0x80 | (0x3f & ch));
              } else {
                  dst[offset++] = (byte) (0xe0 | (0x0f & (ch >> 12)));
                  dst[offset++] = (byte) (0x80 | (0x3f & (ch >> 6)));
                  dst[offset++] = (byte) (0x80 | (0x3f & ch));
              }
          }
      }
docs: Encodes the <i>modified UTF-8</i> bytes corresponding to string {@code s} into the
  byte array {@code dst}, starting at the given {@code offset}.