Java Utililty Methods URL Decode

List of utility methods to do URL Decode

Description

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

Method

Stringdecode(String value, String charset)
decode
String decoded = null;
try {
    decoded = URLDecoder.decode(value, charset);
} catch (UnsupportedEncodingException e) {
    decoded = null;
return decoded;
Stringdecode(String value, String charset)
decode
String result = null;
if (!isEmpty(value)) {
    try {
        result = URLDecoder.decode(value, charset);
    } catch (IOException e) {
        throw new RuntimeException(e);
return result;
Stringdecode(String value, String encoding)
UnsupportedEncodingException -> value returns.
String decode = null;
try {
    decode = URLDecoder.decode(value, encoding);
} catch (UnsupportedEncodingException e) {
    decode = value;
return decode;
StringdecodeAjax(String value)
decode Ajax
String result = null;
try {
    result = decode(value, UTF8);
} catch (UnsupportedEncodingException e) {
    result = "";
    e.printStackTrace();
return result;
...
StringdecodeAjaxParam(final String source)
decode Ajax Param
String target = source;
try {
    target = (source == null ? source : URLDecoder.decode(source, ISO_8859_1));
} catch (final UnsupportedEncodingException ex) {
return target;
String[]decodeArray(final String val)
Return a StringArray resulting from decoding the given String which should have been encoded by encodeArray
if (val == null) {
    return null;
int len = val.length();
if (len == 0) {
    return new String[0];
ArrayList<String> al = new ArrayList<String>();
...
StringdecodeCodedStr(String sourceStr, String targetCharset)
decode Coded Str
String decodedStr;
String changedStr = changeCharset(sourceStr, targetCharset);
if (changedStr != null) {
    try {
        decodedStr = URLDecoder.decode(URLDecoder.decode(changedStr, targetCharset), targetCharset);
    } catch (Exception e) {
        decodedStr = "unknown";
    return decodedStr;
return null;
MapdecodeFormData(String formData)
decode Form Data
Map<String, String> decodedFormData = new HashMap<String, String>();
String[] pairs = formData.split("\\&");
for (int i = 0; i < pairs.length; i++) {
    String[] fields = pairs[i].split("=");
    String name = URLDecoder.decode(fields[0], "UTF-8");
    String value = URLDecoder.decode(fields[1], "UTF-8");
    decodedFormData.put(name, value);
return decodedFormData;
StringdecodeHtmlString(String inputString)
decode Html String
String result;
try {
    result = java.net.URLDecoder.decode(inputString, "UTF8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    result = "";
return result;
...
StringdecodeIfNeeded(String s)
Unfortunately we have code that mindlessly decoded URLs (FileDownloadWindow) which borked (in the case I discovered) magnet uris with encoded parameters (e.g.
if (s == null) {
    return ("");
try {
    int q_pos = s.indexOf('?');
    int a_pos = s.indexOf('&');
    if (q_pos == -1 && a_pos == -1) {
        return (decode(s));
...