Java String Decode decodeText(String str)

Here you can find the source of decodeText(String str)

Description

Encode a string from "default.encoding" to "8859_1".

License

Open Source License

Parameter

Parameter Description
str a source string

Return

encoded string.

Declaration

public static String decodeText(String str) throws UnsupportedEncodingException 

Method Source Code


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

import java.io.UnsupportedEncodingException;

public class Main {
    /**//from w  w w.j av  a 2s . com
     * Encode a string from "default.encoding" to "8859_1".
     * 
     * @param str
     *            a source string
     * @return encoded string.
     * @exception UnsupportedEncodingException
     *                If "default.encoding" is not supported.
     */
    public static String decodeText(String str) throws UnsupportedEncodingException {
        if (getEncoding() == null)
            return str;
        return encodeText(str, getEncoding(), "8859_1");
    }

    /**
     * Default encoding name.
     * 
     * @return Quics properties <code>quics.encoding</code> property value. If
     *         the <code>quics.encoding</code> property value is null, return
     *         null.
     */
    public static String getEncoding() {
        return "euc-kr";
    }

    /**
     * Encode a string from the specific encoding name to other encoding name.
     * 
     * @param str
     *            a source string
     * @param fromEnc
     *            source string encoding name
     * @param toEnc
     *            target encoding name
     * @return encoded string.
     * @exception UnsupportedEncodingException
     *                If the named encoding is not supported.
     */
    public static String encodeText(String str, String fromEnc, String toEnc) throws UnsupportedEncodingException {
        return (str == null) ? null : new String(str.getBytes(fromEnc), toEnc);
    }

    /**
     * Encode a string from &quot;8859_1&quot; to &quot;default.encoding&quot;.
     * 
     * @param str
     *            a source string
     * @return encoded string.
     * @exception UnsupportedEncodingException
     *                If &quot;default.encoding&quot; is not supported.
     */
    public static String encodeText(String str) throws UnsupportedEncodingException {
        if (getEncoding() == null)
            return str;
        return encodeText(str, "8859_1", getEncoding());
    }
}

Related

  1. decodeString(StringReader in)
  2. decodeStringFromByteArray(byte[] data)
  3. decodeStrings(byte[] stringBytes)
  4. decodeText(String encodeText)
  5. decodeText(String s)
  6. decodeTextQuietly(String input)