Java String Decode by Charset decode(String value, Charset charset)

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

Description

Uses URLDecoder to decode a application/x-www-form-urlencoded string, using the given Charset.

License

Apache License

Declaration

public static String decode(String value, Charset charset) 

Method Source Code


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

import static java.nio.charset.StandardCharsets.*;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import java.nio.charset.Charset;

public class Main {
    /** Uses URLDecoder to decode a application/x-www-form-urlencoded string, using the given Charset. */
    public static String decode(String value, Charset charset) {
        try {/*ww w. ja  v  a 2  s .co  m*/
            return URLDecoder.decode(value, charset.name());
        } catch (UnsupportedEncodingException ex) {
            throw new IllegalArgumentException("Characterset is not supported.");
        }
    }

    /** Uses URLDecoder to decode a application/x-www-form-urlencoded string, using UTF-8 as Charset. */
    public static String decode(String value) {
        return decode(value, UTF_8);
    }
}

Related

  1. decode(final String str, final Charset charset)
  2. decode(String s, Charset encoding)
  3. decode(String url, Charset charset)
  4. decode(String value, Charset charset)
  5. decodeCharset(String value, String charset)
  6. decodeComponent(final String s, final Charset charset)
  7. decodeFormFields(final String content, final Charset charset)