coderUtil
来源:互联网 发布:ping网络测试 编辑:程序博客网 时间:2024/06/17 21:59
package cn.gz.encoder;
/**
* @author guozhong
* @version 版本1.0
* 编码的工具类
*
*/
public class CoderUtil {
/**
* @param 参数字节数组
* @return 用utf-8解码
* @throws 编码异常
*
*/
public static String utfDecode(byte[] bytes) throws Exception {
return new String(bytes, "utf-8");
}
/**
* @param 字符串
* @return 解码utf-8
* @throws Exception
*/
public static byte[] utfEncode(String code) throws Exception {
return code.getBytes("utf-8");
}
/**
* @param 参数
* 字节数组
* @return 用gbk解码
* @throws 编码异常
*
*/
public static String gbkDecode(byte[] bytes) throws Exception {
return new String(bytes, "gbk");
}
/**
* @param 字符串
* @return 解码gbk
* @throws Exception
*/
public static byte[] gbkEncode(String code) throws Exception {
return code.getBytes("gbk");
}
/**
* @param 参数
* 字节数组
* @return 用iso8859-1解码
* @throws 编码异常
*
*/
public static String isoDecode(byte[] bytes) throws Exception {
return new String(bytes, "iso8859-1");
}
/**
* @param 字符串
* @return 解码iso
* @throws Exception
*/
public static byte[] isoEncode(String code) throws Exception {
return code.getBytes("iso");
}
}
/**
* @author guozhong
* @version 版本1.0
* 编码的工具类
*
*/
public class CoderUtil {
/**
* @param 参数字节数组
* @return 用utf-8解码
* @throws 编码异常
*
*/
public static String utfDecode(byte[] bytes) throws Exception {
return new String(bytes, "utf-8");
}
/**
* @param 字符串
* @return 解码utf-8
* @throws Exception
*/
public static byte[] utfEncode(String code) throws Exception {
return code.getBytes("utf-8");
}
/**
* @param 参数
* 字节数组
* @return 用gbk解码
* @throws 编码异常
*
*/
public static String gbkDecode(byte[] bytes) throws Exception {
return new String(bytes, "gbk");
}
/**
* @param 字符串
* @return 解码gbk
* @throws Exception
*/
public static byte[] gbkEncode(String code) throws Exception {
return code.getBytes("gbk");
}
/**
* @param 参数
* 字节数组
* @return 用iso8859-1解码
* @throws 编码异常
*
*/
public static String isoDecode(byte[] bytes) throws Exception {
return new String(bytes, "iso8859-1");
}
/**
* @param 字符串
* @return 解码iso
* @throws Exception
*/
public static byte[] isoEncode(String code) throws Exception {
return code.getBytes("iso");
}
}