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

StringparseStringParamAndDecode(String inParam, String defaultVal, String charset)
Parses and decodes and Sanitize the given inParam
if (inParam == null) {
    return defaultVal;
try {
    return parseStringParam(URLDecoder.decode(inParam, charset), defaultVal);
} catch (UnsupportedEncodingException e) {
    return defaultVal;
StringpathDecode(String path)
path Decode
if (path != null) {
    path = path.replace("+", "%2b");
    path = URLDecoder.decode(path, "UTF-8");
return path;
StringpathDecode(String path)
path Decode
return URLDecoder.decode(path, "UTF-8");
StringpercentDecode(String encodedString, String messageEncoding)
Percent decodes a string
try {
    return URLDecoder.decode(encodedString, messageEncoding);
} catch (UnsupportedEncodingException uee) {
    uee.printStackTrace();
return null;
StringpercentDecode(String str, boolean plusToSpace)
Decodes strings that have been percent encoded.
char[] buf = null;
int count = 0; 
final int len = str.length();
for (int i = 0; i < len;) {
    char c = str.charAt(i);
    if (c == '%') {
        if (i + 2 >= len) {
            throw new IllegalArgumentException();
...
StringsafeDecode(String s)
safe Decode
try {
    return URLDecoder.decode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return s;
Stringunescape(String s)
unescape UTF8/URL encoded strings
try {
    return URLDecoder.decode(s, "UTF-8");
} catch (Exception e) {
    return s;
Stringunescape(String string)
Does a URL decoding of the string.
return unescape(string, '%');
Stringunescape(String theString)
unescape
if (theString == null) {
    return null;
for (int i = 0; i < theString.length(); i++) {
    char nextChar = theString.charAt(i);
    if (nextChar == '%' || nextChar == '+') {
        try {
            return URLDecoder.decode(theString, "UTF-8");
...
StringurlDecode(String s)
This utility method is for converting from a MIME format called "x-www-form-urlencoded" to a String

To convert to a String, each character is examined in turn:

  • The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        switch (c) {
        case '+':
            sb.append(' ');
            break;
        case '%':
    ...