package com.sinosoft.cm.common; import java.io.IOException; import java.io.Reader; import java.sql.SQLException; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import com.sinosoft.common.excel.JsonPluginsUtil; import net.sf.json.JSONObject; import nl.justobjects.pushlet.util.Sys; import flex.messaging.io.ArrayList; public class StringUtils { public StringUtils() { } /** * 将clob转换为字符串 * @param clob * @return * @throws SQLException */ public static String clobToString(java.sql.Clob clob) throws SQLException{ if(clob == null) { return null; } Reader inStreamDoc = clob.getCharacterStream(); char[] tempDoc = new char[(int) clob.length()]; try { inStreamDoc.read(tempDoc); inStreamDoc.close(); } catch (IOException e) { e.printStackTrace(); } return new String(tempDoc); } public static String listToQueryIn(List list) throws Exception{ if(list==null||0==list.size())throw new Exception("List集合不能为空或者长度为0"); StringBuffer sb=new StringBuffer(); for(int i=0;i> listMapToMapList(List> list) throws Exception{ Map> map=new HashMap>(); if(null==list)throw new Exception("listMapToMapList(List> list):参数为空或者长度为0;"); for(String listName : list.get(0).keySet()){ map.put(listName, new ArrayList()); } for(Map listItem : list){ for(String listItemKey:listItem.keySet() ){ map.get(listItemKey).add(listItem.get(listItemKey)); } } return map; } public static String listToQueryInString(List list){ StringBuffer sb=new StringBuffer(); for(String str : list){ sb.append("'"+new StringBuffer(str)+"',"); } sb.delete(sb.length()-1, sb.length()); return sb.toString(); } public static List stringToList(String str,String splite){ String spliteStr=str.substring(1, str.lastIndexOf("'")); String[] bb=spliteStr.split(splite); List list=new ArrayList(); for(int i=0,len=bb.length;i> map){ StringBuffer sb=new StringBuffer("{"); for(String key:map.keySet()){ if(map.get(key) instanceof Map){ sb.append("\""+key+"\":").append(mapToJson(map.get(key))).append(","); }else{ sb.append("\""+key+"\":\"").append(map.get(key)).append("\","); } } sb.deleteCharAt(sb.lastIndexOf(",")); sb.append("}"); return sb.toString(); } /* public static void main(String[] args) { Map> map=new HashMap>(); for(int index=0;index<10;index++){ Map map1=new HashMap(); map1.put("avc"+index, "abcd"); map1.put("avw"+index, "abcd"); map.put("aaaa"+index, map1); } String str=ToJson(map); System.out.println("======"+str); }*/ /** * 将map>>集合转换为json对象; * @param map * @return */ /** * 将map>>集合转换为json对象; * @param map * @return */ public static List MapToJson(Map>> map){ List list=new ArrayList(); for(String strName : map.keySet()){ List strList=listToJson(map.get(strName)); String str="{\"name\":\""+strName+"\" ,\"rows\":"+ listToJson(strList)+"}"; list.add(str); } //System.out.println("MapToJson="+list); return list; } public static Map>> packetMap(List> list,String packetKey){ Map>> mapList=new HashMap>>(); for(Map map:list){ if(!mapList.containsKey(map.get(packetKey))){ mapList.put(map.get(packetKey), new ArrayList()); } mapList.get(map.get(packetKey)).add(map); } return mapList; } /** * 将字符串集合转换为JSON字符串 * @param list * @return */ public static String listToJson(List list){ StringBuffer sb=new StringBuffer("["); for(String str : list){ sb.append(new StringBuffer(str)).append(","); } if(sb.length()>1){ sb.delete(sb.length()-1,sb.length()); } sb.append("]"); //System.out.println("listToJson sb.toString()="+sb.toString()); return sb.toString();//JsonPluginsUtil.beanListToJson(list); } /** * 将list集合 * @param list * @return */ public static List listToJson(List> list){ List listJson=new ArrayList(); for(Map map : list){ listJson.add(mapToJson(map)); //System.out.println("mapInlistToJson="+listJson); } //System.out.println("listToJson="+listJson); return listJson; } /** * 将map转换为json字符串 * @param map * @return */ public static String mapToJson(Map map){ StringBuffer sb=new StringBuffer("{"); for(String key:map.keySet()){ sb.append("\""+new StringBuffer(key)+"\":").append("\""+new StringBuffer(map.get(key))+"\","); } sb.deleteCharAt(sb.length()-1); sb.append("}"); //System.out.println("mapToJson="+sb.toString()); return sb.toString(); } /** * * @param sql * @return */ public static List stringToList2(String str,String split){ List list=new ArrayList(); if(!str.contains(split)){ list.add(str); }else{ String[] strArr=str.split(split); Collections.addAll(list,strArr); } return list; } /** * 将sql语句截取会可接受查询结果集的 * @param str * @param split * @return */ public static List sqlStringToListLabel(String str,String split){ List list=new ArrayList(); str=subSqlLabel(str.trim()); String[] strArr=str.split(split); getSqlLabelFromArr(list,strArr); return list; } /** * 将查询字段数组转化为可接受查询结果集字段 * @param list * @param arr * @return */ public static List getSqlLabelFromArr(List list, String[] arr){ for(int index=0,len=arr.length;index list) throws Exception { if(list==null) throw new Exception("集合长度为空"); System.out.println(str.split(reg).length+":"+list.size()); if((str.split(reg.replace("\\", "")).length-1)!=list.size()) throw new Exception("替换长度不匹配"); for(int index=0,len=list.size();index> list,String columnLabel,String insertStr) { StringBuffer sb=new StringBuffer(); if(list.size()==0 || columnLabel==null || columnLabel.toUpperCase()=="NULL"|| "".equals(columnLabel)) return null; if(list.size()==0) return list.get(0).get(columnLabel); for(int index=0,len=list.size();index list,String insertStr) { if(list==null) return null; if(list.size()==0) return list.get(0); StringBuffer sb=new StringBuffer(); for(int index=0,len=list.size();index