Java URL Decode decodeCodedStr(String sourceStr, String targetCharset)

Here you can find the source of decodeCodedStr(String sourceStr, String targetCharset)

Description

decode Coded Str

License

Open Source License

Declaration

public static String decodeCodedStr(String sourceStr, String targetCharset)
        throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Main {

    public static String decodeCodedStr(String sourceStr, String targetCharset)
            throws UnsupportedEncodingException {
        String decodedStr;// w  ww  .  j a v  a2  s. co  m
        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;
    }

    public static String changeCharset(String str, String targetCharset) throws UnsupportedEncodingException {
        String targetStr = null;
        if (str != null) {
            byte[] byteString = str.getBytes();
            targetStr = new String(byteString, targetCharset);
        }
        return targetStr;
    }
}

Related

  1. decode(String value, String charset)
  2. decode(String value, String encoding)
  3. decodeAjax(String value)
  4. decodeAjaxParam(final String source)
  5. decodeArray(final String val)
  6. decodeFormData(String formData)
  7. decodeHtmlString(String inputString)
  8. decodeIfNeeded(String s)
  9. decodeInternally(String encoded)