Java URL Decode decode(String value)

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

Description

#decode(String,String) with "UTF-8" encoding

License

Apache License

Parameter

Parameter Description
value the <code>String</code> to decode

Return

the newly decoded String

Declaration

public static String decode(String value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URLDecoder;

public class Main {
    /**//from  w  w  w .  j a v  a 2 s .  co m
     *
     */
    private static final String DEFAULT_ENCODING = "UTF-8";

    /**
     * {@link #decode(String, String)} with "UTF-8" encoding
     *
     * @param value
     *         the <code>String</code> to decode
     * @return the newly decoded <code>String</code>
     */
    public static String decode(String value) {
        return decode(value, DEFAULT_ENCODING);
    }

    /**
     * Decodes a <code>application/x-www-form-urlencoded</code> string using a specific encoding scheme. The supplied
     * encoding is used to determine what characters are represented by any consecutive sequences of the form
     * "<code>%<i>xy</i></code>".
     * <p/>
     * <em><strong>Note:</strong> The <a href= "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars"> World
     * Wide Web Consortium Recommendation</a> states that UTF-8 should be used. Not doing so may introduce
     * incompatibilites.</em>
     *
     * @param value
     *         the <code>String</code> to decode
     * @param encoding
     *         The name of a supported encoding
     * @return the newly decoded <code>String</code>
     * @throws IllegalArgumentException
     *         If character encoding needs to be consulted, but named character encoding is not supported
     */
    public static String decode(String value, String encoding) throws IllegalArgumentException {
        String decodedValue = null;
        try {
            decodedValue = URLDecoder.decode(value, encoding);
        } catch (Exception e) {
            throw new IllegalArgumentException(e.getMessage());
        }
        return decodedValue;
    }
}

Related

  1. decode(String source, String encoding)
  2. decode(String str)
  3. decode(String str)
  4. decode(String value)
  5. decode(String value)
  6. decode(String value)
  7. decode(String value, String charset)
  8. decode(String value, String charset)
  9. decode(String value, String encoding)