public static String decodeString ( byte [ ] buf , int ofs , int len ) throws CharacterCodingException { if ( ofs < 0 || len < 0 || ofs + len < 0 || ofs + len > buf . length ) { throw new IndexOutOfBoundsException ( ) ; } CharsetDecoder decoder = Charset . forName ( "UTF-8" ) . newDecoder ( ) . onMalformedInput ( CodingErrorAction . REPORT ) . onUnmappableCharacter ( CodingErrorAction . REPORT ) ; return decoder . decode ( ByteBuffer . wrap ( buf , ofs , len ) ) . toString ( ) ; }
Decodes UTF - 8 string from the given buffer .