List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:Main.java
public static String decode(String value, String charset) { String result = null;/* w ww . ja va2s . com*/ if (!TextUtils.isEmpty(value)) { try { result = URLDecoder.decode(value, charset); } catch (IOException e) { throw new RuntimeException(e); } } return result; }
From source file:Main.java
public static Map<String, String> splitQuery(String query) { Map<String, String> query_pairs = new LinkedHashMap<String, String>(); try {//from ww w . j av a 2 s. com String[] pairs = query.split("&"); for (String pair : pairs) { int idx = pair.indexOf("="); query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); } } catch (UnsupportedEncodingException e) { query_pairs.put("error", "UnsupportedEncodingException"); query_pairs.put("error_description", e.getMessage()); } return query_pairs; }
From source file:Main.java
private static String decode(String value) { if (value != null) { try {/*from w w w. j ava 2s . c o m*/ return URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return null; }
From source file:Main.java
public static String extract(String response, Pattern p) { Matcher matcher = p.matcher(response); if (matcher.find() && matcher.groupCount() >= 1) { try {// w w w . j a v a2s . c o m return URLDecoder.decode(matcher.group(1), UTF_8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } throw new RuntimeException( "Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null); }
From source file:Main.java
public static String decodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLDecoder.decode(tokenizer.nextToken(), characterSet)); builder.append(delimiter);/*w w w . ja va2 s.c o m*/ } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); }
From source file:Main.java
public static String toURLDecoded(String paramString) { if (paramString == null || paramString.equals("")) { LogD("toURLDecoded error:" + paramString); return ""; }/*from w w w . j av a 2 s . c o m*/ try { String str = new String(paramString.getBytes(), "UTF-8"); str = URLDecoder.decode(str, "UTF-8"); return str; } catch (Exception localException) { LogE("toURLDecoded error:" + paramString, localException); } return ""; }
From source file:Main.java
public static Map<String, List<String>> getQueryParams(String url) { try {/*from ww w. ja va2 s .co m*/ Map<String, List<String>> params = new HashMap<String, List<String>>(); String[] urlParts = url.split("\\?"); if (urlParts.length > 1) { String query = urlParts[1]; for (String param : query.split("&")) { String[] pair = param.split("="); String key = URLDecoder.decode(pair[0], "UTF-8"); String value = ""; if (pair.length > 1) { value = URLDecoder.decode(pair[1], "UTF-8"); } List<String> values = params.get(key); if (values == null) { values = new ArrayList<String>(); params.put(key, values); } values.add(value); } } return params; } catch (UnsupportedEncodingException ex) { throw new AssertionError(ex); } }
From source file:Main.java
public static String decodeURL(String s, String charsetName) { if (s == null) { return null; }// w w w .j ava 2s.com try { if (TextUtils.isEmpty(charsetName)) { charsetName = Charset.defaultCharset().displayName(); } return URLDecoder.decode(s, charsetName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static void DoConvertAttrsToStringMap(Attributes atts, HashMap<String, String> MapDest) { for (int attrsIndex = 0; attrsIndex < atts.getLength(); attrsIndex++) { String AttrName = atts.getLocalName(attrsIndex); String AttrValue = atts.getValue(attrsIndex); try {//from w ww . j a v a2 s . co m AttrValue = URLDecoder.decode(AttrValue, URL_DECODE_TYPE); MapDest.put(AttrName, AttrValue); } catch (UnsupportedEncodingException e) { // TODO } //Log.w("FCXML", "DoConvertAttrsToStringMap: Index: " + attrsIndex + " Name: " + AttrName + " Value " + AttrValue ); } }
From source file:Main.java
@Deprecated public static HashMap<String, String> splitParams(String params) { if (TextUtils.isEmpty(params)) { return new HashMap<String, String>(); }/*w ww . ja va 2 s . co m*/ String[] kvs = params.split("&"); HashMap<String, String> map = new HashMap<String, String>(kvs.length); for (String string : kvs) { String[] kv = string.split("="); if (kv.length == 2) { try { kv[1] = URLDecoder.decode(kv[1], "utf-8"); } catch (UnsupportedEncodingException e) { } map.put(kv[0], kv[1]); } } return map; }