public static String decodeString(String source) throws URISyntaxException {
  if (source == null) {
    return source;
  }
  int i;
  if ((i=source.indexOf(QUOTE_MARKER)) == -1) {
    return source;
  }
  ByteArrayOutputStream decoded=new ByteArrayOutputStream();
  try {
    decoded.write(toBytes(source.substring(0,i)));
    int len=source.length();
    for (; i < len; i++) {
      char ch=source.charAt(i);
      if (ch == QUOTE_MARKER) {
        if ((i + 2) >= len) {
          ch=ENCODING_ERROR_MARKER;
        }
 else {
          try {
            ch=(char)Integer.parseInt(source.substring(i + 1,i + 3),16);
          }
 catch (          NumberFormatException nfe) {
            throw new URISyntaxException(source,"Invalid escape value");
          }
          decoded.write(ch);
        }
        i+=2;
      }
 else {
        decoded.write(ch);
      }
    }
    return new String(decoded.toByteArray(),"UTF8");
  }
 catch (  IOException e) {
    e.printStackTrace();
    return null;
  }
}

public static String decodeString ( String source ) throws URISyntaxException { if ( source == null ) { return source ; } int i ; if ( ( i = source . indexOf ( QUOTE_MARKER ) ) == - 1 ) { return source ; } ByteArrayOutputStream decoded = new ByteArrayOutputStream ( ) ; try { decoded . write ( toBytes ( source . substring ( 0 , i ) ) ) ; int len = source . length ( ) ; for ( ; i < len ; i ++ ) { char ch = source . charAt ( i ) ; if ( ch == QUOTE_MARKER ) { if ( ( i + 2 ) >= len ) { ch = ENCODING_ERROR_MARKER ; } else { try { ch = ( char ) Integer . parseInt ( source . substring ( i + 1 , i + 3 ) , 16 ) ; } catch ( NumberFormatException nfe ) { throw new URISyntaxException ( source , "Invalid escape value" ) ; } decoded . write ( ch ) ; } i += 2 ; } else { decoded . write ( ch ) ; } } return new String ( decoded . toByteArray ( ) , "UTF8" ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; return null ; } }
a utility method to decode a string .
