public static String readCharacterSizedString(InputStream stream) throws IOException {
  StringBuilder result=new StringBuilder();
  int strLen=readUINT16(stream);
  int character=stream.read();
  character|=stream.read() << 8;
  do {
    if (character != 0) {
      result.append((char)character);
      character=stream.read();
      character|=stream.read() << 8;
    }
  }
 while (character != 0 || (result.length() + 1) > strLen);
  if (strLen != (result.length() + 1)) {
    throw new IllegalStateException("Invalid Data for current interpretation");
  }
  return result.toString();
}

public static String readCharacterSizedString ( InputStream stream ) throws IOException { StringBuilder result = new StringBuilder ( ) ; int strLen = readUINT16 ( stream ) ; int character = stream . read ( ) ; character |= stream . read ( ) << 8 ; do { if ( character != 0 ) { result . append ( ( char ) character ) ; character = stream . read ( ) ; character |= stream . read ( ) << 8 ; } } while ( character != 0 || ( result . length ( ) + 1 ) > strLen ) ; if ( strLen != ( result . length ( ) + 1 ) ) { throw new IllegalStateException ( "Invalid Data for current interpretation" ) ; } return result . toString ( ) ; }
this method reads a utf - 16 string , which length is given on the number of characters it consists of . < br > the stream must be at the number of characters . this number contains the terminating zero character ( uint16 ) .
