Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:Main.java

public static String getDecoder(String str) {
    try {/*from w w w . j  av a 2  s . co  m*/
        return URLDecoder.decode(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

/**
 * From http://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection
 *//*from w w  w  .  j a  v a2  s  .  co m*/
public static Map<String, List<String>> splitQuery(String urlQuery) throws UnsupportedEncodingException {
    final Map<String, List<String>> query_pairs = new LinkedHashMap<>();
    final String[] pairs = urlQuery.split("&");
    for (String pair : pairs) {
        final int idx = pair.indexOf("=");
        final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
        if (!query_pairs.containsKey(key)) {
            query_pairs.put(key, new LinkedList<String>());
        }
        final String value = idx > 0 && pair.length() > idx + 1
                ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8")
                : null;
        query_pairs.get(key).add(value);
    }
    return query_pairs;
}

From source file:Main.java

public static String urlDecode(String s) {
    try {//from   ww w .j  av  a 2  s. c  om
        return URLDecoder.decode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("could not URL decode string: " + s, e);
    }
}

From source file:Main.java

public static String decodeQuery(String url) {
    try {/*  ww  w . j av a 2 s  .c om*/
        return URLDecoder.decode(url, "UTF-8");
    } catch (UnsupportedEncodingException ignore) {
    }

    return url;
}

From source file:Main.java

public static String urlDecode(String str) {
    try {//from   w  w  w .j av a  2 s .c  o  m
        return URLDecoder.decode(str, UTF8);
    } catch (UnsupportedEncodingException ex) {
        return str;
    }
}

From source file:com.threerings.getdown.util.ConnectionUtil.java

/**
 * Opens a connection to a URL, setting the authentication header if user info is present.
 *//*from ww  w  . j a va  2s .  c o  m*/
public static URLConnection open(URL url) throws IOException {
    URLConnection conn = url.openConnection();

    // If URL has a username:password@ before hostname, use HTTP basic auth
    String userInfo = url.getUserInfo();
    if (userInfo != null) {
        // Remove any percent-encoding in the username/password
        userInfo = URLDecoder.decode(userInfo, "UTF-8");
        // Now base64 encode the auth info and make it a single line
        String encoded = Base64.encodeBase64String(userInfo.getBytes("UTF-8")).replaceAll("\\n", "")
                .replaceAll("\\r", "");
        conn.setRequestProperty("Authorization", "Basic " + encoded);
    }

    return conn;
}

From source file:edu.northwestern.bioinformatics.studycalendar.core.editors.EditorUtils.java

public static String getDecodedString(String str) {
    try {/*from  w  ww .  j a va2s.c o  m*/
        return URLDecoder.decode(str, CHAR_ENCODE);
    } catch (UnsupportedEncodingException e) {
        throw new StudyCalendarError("Unsupported character encoding", e);
    }
}

From source file:Main.java

public static String urlDecode(String s) {
    try {//ww  w.j  av a2  s .co  m
        return URLDecoder.decode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            try {
                params.putString(URLDecoder.decode(v[0], "UTF-8"), URLDecoder.decode(v[1], "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();/*from  w ww.j  a  v  a2  s.com*/

            }
        }
    }
    return params;
}

From source file:com.kth.common.utils.etc.URLCoderUtil.java

/** URL? URL Decode. */
public static String decode(final String content, final String encoding) {
    try {//from  w  w w  . j  av  a  2  s. com
        return URLDecoder.decode(content, encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
    } catch (UnsupportedEncodingException problem) {
        throw new IllegalArgumentException(problem);
    }
}