Java URL Decode decode(String encoded)

Here you can find the source of decode(String encoded)

Description

decode

License

Open Source License

Declaration

public static String decode(String encoded) throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

public class Main {
    public static String decode(String encoded) throws UnsupportedEncodingException {
        String temp = URLDecoder.decode(encoded.toString(), "UTF-8");
        if (temp.length() == encoded.length()) {
            // Decoding was not necessary since it didn't get smaller to return the original.
            return encoded;
        } else {/*w  w w  .ja  v  a 2 s .  co m*/
            return temp;
        }
    }

    public static String decode(String encoded, String encoding) throws UnsupportedEncodingException {
        String temp = URLDecoder.decode(encoded.toString(), encoding);
        if (temp.length() == encoded.length()) {
            // Decoding was not necessary since it didn't get smaller to return the original.
            return encoded;
        } else {
            return temp;
        }
    }
}

Related

  1. decode(final String content, final String encoding)
  2. decode(final String s, final String enc)
  3. decode(final String string)
  4. decode(Object value)
  5. decode(String content)
  6. decode(String encodeMsg)
  7. decode(String input)
  8. decode(String input)
  9. decode(String path)