package com.renrenliao.im.utils;

import java.io.UnsupportedEncodingException;

public class CharsetUtils {
    public static final String ENCODE_CHARSET = "UTF-8";

    public static final String DECODE_CHARSET = "UTF-8";

    public static String getString(byte[] b, int len) {
        try {
            return new String(b, 0, len, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return new String(b, 0, len);
        }
    }

    public static String getString(byte[] b, int start, int len) {
        try {
            return new String(b, start, len, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return new String(b, start, len);
        }
    }

    public static byte[] getBytes(String str) {
        if (str != null)
            try {
                return str.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                return str.getBytes();
            }
        return new byte[0];
    }
}

