List of utility methods to do URL Build
String | queryStringify(HashMap Converts a Map into an HTTP query string String retval = ""; for (Map.Entry<String, String> pair : qString.entrySet()) { try { retval += URLEncoder.encode(pair.getKey(), "UTF-8") + "=" + URLEncoder.encode(pair.getValue(), "UTF-8"); retval += "&"; } catch (UnsupportedEncodingException e) { throw new RuntimeException("Apparently Unicode isn't a good encoding"); ... |
Map | queryStringToMap(String query, Boolean decode) query String To Map HashMap<String, String> hashMap = new HashMap<String, String>(); String[] encodedPairs = query.split("&"); for (String pair : encodedPairs) { String[] splitPair = pair.split("=", -1); if (splitPair.length != 2) { throw new RuntimeException("query string not properly formatted"); String encodedKey = splitPair[0]; ... |
Map | queryStringToMap(String queryString) Parses and form-urldecodes a querystring-like string into a map Map<String, String> result = new HashMap<String, String>(); if (queryString != null && queryString.length() > 0) { for (String param : queryString.split(PARAM_SEPARATOR)) { String pair[] = param.split(PAIR_SEPARATOR); String key = formURLDecode(pair[0]); String value = pair.length > 1 ? formURLDecode(pair[1]) : EMPTY_STRING; result.put(key, value); return result; |
Map | queryStringToMap(String queryString, String charset) Convert a query string into a map. Map<String, String> result = new HashMap<>(); String[] pairs = queryString.split("\\&"); for (String pair : pairs) { StringTokenizer kp = new StringTokenizer(pair, "="); String key = kp.nextToken(); String value = "true"; if (kp.hasMoreTokens()) { value = URLDecoder.decode(kp.nextToken(), charset); ... |
Map | queryStringToMap(String queryString, String charSet) query String To Map if (queryString == null) { throw new IllegalArgumentException("queryString must be specified"); int index = queryString.indexOf("?"); if (index > 0) { queryString = queryString.substring(index + 1); String[] keyValuePairs = queryString.split("&"); ... |
Map | queryToMap(final String query) query To Map final Map<String, String> map = new HashMap<String, String>(); final String[] keyValuePairs = query.split("&"); for (String KeyValuePair : keyValuePairs) { final String[] KeyValue = KeyValuePair.split("="); try { map.put(URLDecoder.decode(KeyValue[0], "UTF-8"), Strings.nullToEmpty(KeyValue[1])); } catch (UnsupportedEncodingException e) { throw new RuntimeException("This method requires UTF-8 encoding support", e); ... |
Map | queryToParams(String query) Parse given query string of the form name1=value1&name2=value2 and return it as Map
Map<String, String> query_pairs = new HashMap<String, String>(); 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")); return query_pairs; ... |