public static String decode(String s,Type t){
  if (s == null) {
    throw new IllegalArgumentException();
  }
  final int n=s.length();
  if (n == 0) {
    return s;
  }
  if (s.indexOf('%') < 0) {
    if (t == Type.QUERY_PARAM) {
      if (s.indexOf('+') < 0) {
        return s;
      }
    }
 else {
      return s;
    }
  }
 else {
    if (n < 2) {
      throw new IllegalArgumentException("Malformed percent-encoded octet at index 1");
    }
    if (s.charAt(n - 2) == '%') {
      throw new IllegalArgumentException("Malformed percent-encoded octet at index " + (n - 2));
    }
  }
  if (t == null) {
    return decode(s,n);
  }
switch (t) {
case HOST:
    return decodeHost(s,n);
case QUERY_PARAM:
  return decodeQueryParam(s,n);
default :
return decode(s,n);
}
}

public static String decode ( String s , Type t ) { if ( s == null ) { throw new IllegalArgumentException ( ) ; } final int n = s . length ( ) ; if ( n == 0 ) { return s ; } if ( s . indexOf ( '%' ) < 0 ) { if ( t == Type . QUERY_PARAM ) { if ( s . indexOf ( '+' ) < 0 ) { return s ; } } else { return s ; } } else { if ( n < 2 ) { throw new IllegalArgumentException ( "Malformed percent-encoded octet at index 1" ) ; } if ( s . charAt ( n - 2 ) == '%' ) { throw new IllegalArgumentException ( "Malformed percent-encoded octet at index " + ( n - 2 ) ) ; } } if ( t == null ) { return decode ( s , n ) ; } switch ( t ) { case HOST : return decodeHost ( s , n ) ; case QUERY_PARAM : return decodeQueryParam ( s , n ) ; default : return decode ( s , n ) ; } }
decodes characters of a string that are percent - encoded octets using utf - 8 decoding ( if needed ) . < p > it is assumed that the string is valid according to an ( unspecified ) uri component type . if a sequence of contiguous percent - encoded octets is not a valid utf - 8 character then the octets are replaced with ' \ ufffd ' . < p > if the uri component is of type host then any " % " found between " [ ] " is left alone . it is an ipv6 literal with a scope_id . < p > if the uri component is of type query_param then any " + " is decoded as as ' ' . < p >
