Java Utililty Methods URL Query Build

List of utility methods to do URL Query Build

Description

The list of methods to do URL Query Build are organized into topic(s).

Method

Map>getQueryParams(String url)
get Query Params
try {
    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");
...
StringgetQueryString(final Map parameters)
Construct a new new URL from the baseUrl with the additional query string parameters.
final StringBuilder query = new StringBuilder();
appendQuery(query, parameters);
return query.toString();
StringgetQueryString(final Map parameters, final boolean encode)
get Query String
final String ENCODING = "UTF-8"; 
final String EQUALS = "="; 
final String AMPERSAND = "&"; 
final String EQUALS_ENCODED = encode ? URLEncoder.encode(EQUALS, ENCODING) : EQUALS;
final String AMPERSAND_ENCODED = encode ? URLEncoder.encode(AMPERSAND, ENCODING) : AMPERSAND;
final StringBuffer queryString = new StringBuffer();
for (Iterator<Map.Entry<String, Object>> iterator = parameters.entrySet().iterator(); iterator.hasNext();) {
    final Map.Entry<String, Object> entry = iterator.next();
...
StringgetQueryString(Map parameters)
get Query String
if (parameters != null) {
    StringBuilder result = new StringBuilder();
    boolean isFirst = true;
    for (Entry<String, Object> entry : parameters.entrySet()) {
        if (!(entry.getValue() instanceof File)) {
            if (!isFirst) {
                result.append("&");
            result.append(entry.getKey()).append("=").append(encodeParameter(entry.getValue().toString()));
            if (isFirst)
                isFirst = false;
    return result.toString();
return "";
StringgetQueryString(Map parameters)
Gets a valid query-string based on the given parameters.
StringBuilder result = new StringBuilder();
if (parameters != null) {
    for (Entry<String, String> param : parameters.entrySet()) {
        final String encodedName = encode(param.getKey(), null);
        final String value = param.getValue();
        final String encodedValue = value != null ? encode(value, null) : "";
        if (result.length() > 0) {
            result.append(PARAMETER_SEPARATOR);
...
StringgetQueryString(String url)
get Query String
final String query;
try {
    query = new URL(url).getQuery();
    return query == null ? "" : query;
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
StringgetQueryUrl(String word)
get Query Url
return URL_HOST + "/pl?key=" + URLEncoder.encode(word, "UTF-8");
StringgetQueryUrl(String word, Integer page)
get Query Url
if (word == null) {
    return null;
String qp = (page == null) ? "" : ("&page=" + page);
return URL_HOST + "/results?search_query=" + URLEncoder.encode(word, "UTF-8") + "&sm=3" + qp;
URLgetQueryURL(URL baseUrl, String[] parameters)
Using the resourceURL, build a query URL.
StringBuilder sb = new StringBuilder();
if (parameters != null) {
    sb.append("?");
    for (String s : parameters) {
        sb.append(s);
        sb.append("&");
    sb.deleteCharAt(sb.length() - 1);
...
MapgetQueryValues(String input)
get Query Values
Map<String, String> ret = new HashMap<String, String>();
String[] params = input.split("&");
for (String param : params) {
    try {
        int eq = param.indexOf("=");
        if (eq > 0) {
            String key = param.substring(0, eq);
            String value = param.substring(eq + 1, param.length());
...