protected String readUTF ( ) throws IOException { int len = ( is . read ( ) << 8 ) + is . read ( ) ; StringBuffer sb = new StringBuffer ( ) ; while ( len > 0 ) { int d1 = is . read ( ) ; if ( d1 < 0 ) return sb . toString ( ) ; else if ( d1 < 0x80 ) { len -- ; sb . append ( ( char ) d1 ) ; } else if ( ( d1 & 0xe0 ) == 0xc0 ) { len -= 2 ; sb . append ( ( ( d1 & 0x1f ) << 6 ) + ( is . read ( ) & 0x3f ) ) ; } else if ( ( d1 & 0xf0 ) == 0xe0 ) { len -= 3 ; sb . append ( ( ( d1 & 0x0f ) << 12 ) + ( ( is . read ( ) & 0x3f ) << 6 ) + ( is . read ( ) & 0x3f ) ) ; } else throw new IOException ( "utf-8 encoding error" ) ; } return sb . toString ( ) ; }
Reads a UTF - 8 string .