public static byte [ ] encodeUTF8 ( String str ) { byte [ ] bytes = allocateReuseBytes ( str . length ( ) * MAX_BYTES_PER_CHAR ) ; int len = encodeUTF8 ( str , bytes ) ; return Arrays . copyOf ( bytes , len ) ; }
This method must have the same result with JDK s String . getBytes .