package cn.feast.coding.tools;

import java.io.UnsupportedEncodingException;

public class StringEncodeUtils {

    public static String utf8ToIso88591(String str) {
        String ret = "";
        try {
            ret = new String(str.getBytes("UTF-8"), "ISO-8859-1");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return ret;
    }

    public static String iso88591ToUtf8(String str) {
        String ret = "";
        try {
            ret = new String(str.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return ret;
    }

    public static String gbkToIso88591(String str) {
        String ret = "";
        try {
            ret = new String(str.getBytes("GBK"), "ISO-8859-1");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return ret;
    }

    public static String convertEncode(String str, String source, String replacement) {
        String ret = "";
        try {
            ret = new String(str.getBytes(source), replacement);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return ret;
    }
}
