package com.jqmobile.core.utils.plain; import java.io.UnsupportedEncodingException; import com.jqmobile.core.http.HttpUtils; /** * 字符串工具类 * @author liuhongbin */ public final class StringUtils { /** * 判断是否为空串(是返回true) * * @param str 待处理字符串 * @param trim 是否首尾去空 * @return 当字符串为空时返回true,否则返回false * @author liuhongbin */ public static boolean isEmpty(String str, boolean trim) { String value = str; if (value == null) { return true; } if (trim) { value = value.trim(); } if ("".equalsIgnoreCase(value)) { return true; } return false; } /** * 判断是否为非空串(是返回false) * * @param str 待处理字符串 * @param trim 是否首尾去空 * @return 当字符串为空时返回false,否则返回true * @author liuhongbin */ public static boolean isNotEmpty(String str, boolean trim) { return !isEmpty(str, trim); } public static String valueOfBytes(String str){ try { return valueOf(str.getBytes(HttpUtils.CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } public static String valueOf(byte[] bytes) { StringBuilder s = new StringBuilder(); for(int i=0; i<bytes.length; i++){ s.append(bytes[i]); if(i != bytes.length-1){ s.append(","); } } return s.toString(); } public static String valueOfBytesStr(String str){ String[] ss = str.split(","); byte[] bs = new byte[ss.length]; for(int i=0; i<ss.length; i++){ bs[i] = Byte.parseByte(ss[i]); } try { return new String(bs, HttpUtils.CHARSET); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } }