private int utfLength(String s){
  int len=s.length();
  int utfLen=0;
  for (int off=0; off < len; ) {
    int size=Math.min(len - off,CHAR_BUF_SIZE);
    s.getChars(off,off + size,cbuf,0);
    for (int pos=0; pos < size; pos++) {
      char c=cbuf[pos];
      if (c >= 0x0001 && c <= 0x007F)       utfLen++;
 else       utfLen+=c > 0x07FF ? 3 : 2;
    }
    off+=size;
  }
  return utfLen;
}

private int utfLength ( String s ) { int len = s . length ( ) ; int utfLen = 0 ; for ( int off = 0 ; off < len ; ) { int size = Math . min ( len - off , CHAR_BUF_SIZE ) ; s . getChars ( off , off + size , cbuf , 0 ) ; for ( int pos = 0 ; pos < size ; pos ++ ) { char c = cbuf [ pos ] ; if ( c >= 0x0001 && c <= 0x007F ) utfLen ++ ; else utfLen += c > 0x07FF ? 3 : 2 ; } off += size ; } return utfLen ; }
returns the length in bytes of the utf encoding of the given string .
