public static int chars2utf(char[] src, int sindex,
                                byte[] dst, int dindex,
                                int len) {
        int j = dindex;
        int limit = sindex + len;
        for (int i = sindex; i < limit; i++) {
            char ch = src[i];
            if (1 <= ch && ch <= 0x7F) {
                dst[j++] = (byte)ch;
            } else if (ch <= 0x7FF) {
                dst[j++] = (byte)(0xC0 | (ch >> 6));
                dst[j++] = (byte)(0x80 | (ch & 0x3F));
            } else {
                dst[j++] = (byte)(0xE0 | (ch >> 12));
                dst[j++] = (byte)(0x80 | ((ch >> 6) & 0x3F));
                dst[j++] = (byte)(0x80 | (ch & 0x3F));
            }
        }
        return j;
    }
public static int chars2utf ( char [ ] src , int sindex , byte [ ] dst , int dindex , int len ) { int j = dindex ; int limit = sindex + len ; for ( int i = sindex ; i < limit ; i ++ ) { char ch = src [ i ] ; if ( 1 <= ch && ch <= 0x7F ) { dst [ j ++ ] = ( byte ) ch ; } else if ( ch <= 0x7FF ) { dst [ j ++ ] = ( byte ) ( 0xC0 | ( ch > > 6 ) ) ; dst [ j ++ ] = ( byte ) ( 0x80 | ( ch & 0x3F ) ) ; } else { dst [ j ++ ] = ( byte ) ( 0xE0 | ( ch > > 12 ) ) ; dst [ j ++ ] = ( byte ) ( 0x80 | ( ( ch > > 6 ) & 0x3F ) ) ; dst [ j ++ ] = ( byte ) ( 0x80 | ( ch & 0x3F ) ) ; } } return j ; }
Copy characters in source array to bytes in target array,
converting them to Utf8 representation.
The target array must be large enough to hold the result.
returns first index in `dst' past the last copied byte.
@param src        The array holding the characters to convert.
@param sindex     The start index from which characters are converted.
@param dst        The array holding the converted characters..
@param dindex     The start index from which converted bytes
are written.
@param len        The maximum number of characters to convert.