public static int getTextUtfLength(Text t) {
    byte[] data = t.getBytes();
    int len = 0;
    for (int i = 0; i < t.getLength(); i++) {
      if (isUtfStartByte(data[i])) {
        len++;
      }
    }
    return len;
  }
Checks if b is the first byte of a UTF-8 character.
common/src/java/org/apache/hive/common/util/HiveStringUtils.java