public static int findLeadingSpaces(byte[] bytes, int start, int length) {
    int numSpaces;
    for (numSpaces = 0; numSpaces < length; ++numSpaces) {
      int curPos = start + numSpaces;
      if (isAscii(bytes[curPos]) && Character.isWhitespace(bytes[curPos])) {
        continue;
      }
      break; // non-space character
    }
    return (numSpaces - start);
  }
Returns the number of leading whitespace characters in the utf-8 string
common/src/java/org/apache/hive/common/util/HiveStringUtils.java