code: public static int lengthOfCodePointFromStartByte(byte startByte)
      {
          int unsignedStartByte = startByte & 0xFF;
          if (unsignedStartByte < 0x80) {
              // normal ASCII
              // 0xxx_xxxx
              return 1;
          }
          if (unsignedStartByte < 0xc0) {
              // illegal bytes
              // 10xx_xxxx
              throw new InvalidUtf8Exception("Illegal start 0x" + toHexString(unsignedStartByte).toUpperCase() + " of code point");
          }
          if (unsignedStartByte < 0xe0) {
              // 110x_xxxx 10xx_xxxx
              return 2;
          }
          if (unsignedStartByte < 0xf0) {
              // 1110_xxxx 10xx_xxxx 10xx_xxxx
              return 3;
          }
          if (unsignedStartByte < 0xf8) {
              // 1111_0xxx 10xx_xxxx 10xx_xxxx 10xx_xxxx
              return 4;
          }
          // Per RFC3629, UTF-8 is limited to 4 bytes, so more bytes are illegal
          throw new InvalidUtf8Exception("Illegal start 0x" + toHexString(unsignedStartByte).toUpperCase() + " of code point");
      }
docs: Gets the UTF-8 sequence length using the sequence start byte.
  <p>
  Note: This method does not explicitly check for valid UTF-8, and may
  return incorrect results or throw an exception for invalid UTF-8.