public static String readFixedSizeUTF16Str(InputStream stream,int strLen) throws IOException {
  byte[] strBytes=new byte[strLen];
  int read=stream.read(strBytes);
  if (read == strBytes.length) {
    if (strBytes.length >= 2) {
      if (strBytes[strBytes.length - 1] == 0 && strBytes[strBytes.length - 2] == 0) {
        byte[] copy=new byte[strBytes.length - 2];
        System.arraycopy(strBytes,0,copy,0,strBytes.length - 2);
        strBytes=copy;
      }
    }
    return new String(strBytes,"UTF-16LE");
  }
  throw new IllegalStateException("Couldn't read the necessary amount of bytes.");
}

public static String readFixedSizeUTF16Str ( InputStream stream , int strLen ) throws IOException { byte [ ] strBytes = new byte [ strLen ] ; int read = stream . read ( strBytes ) ; if ( read == strBytes . length ) { if ( strBytes . length >= 2 ) { if ( strBytes [ strBytes . length - 1 ] == 0 && strBytes [ strBytes . length - 2 ] == 0 ) { byte [ ] copy = new byte [ strBytes . length - 2 ] ; System . arraycopy ( strBytes , 0 , copy , 0 , strBytes . length - 2 ) ; strBytes = copy ; } } return new String ( strBytes , "UTF-16LE" ) ; } throw new IllegalStateException ( "Couldn't read the necessary amount of bytes." ) ; }
this method reads a utf - 16 encoded string . < br > for the use this method the number of bytes used by current string must be known . < br > the asf specification recommends that those strings end with a terminating zero . however it also says that it is not always the case .
