2014年5月4日 星期日

依byte切中英文混和字串


public static void main(String[] args) {
String tagStr = "你好嗎abcd你好嗎abcd你好嗎abcd你好嗎abcd你好嗎abcd你好嗎abcd你 好嗎abcd你好嗎abcd你好嗎abcd你好嗎你aa1234你好嗎56789";
String[] tag = spiltString(tagStr);
System.out.println(tag[0]+">>>" +tag[1]  );
}

private static String[] spiltString(String tagStr){
int split_1 = tagStr.getBytes().length / 100;
int split_2 = tagStr.getBytes().length % 100;
String[] splitArray = null;
if(split_2 > 0){
splitArray = new String[split_1+1];
} else{
splitArray = new String[split_1];
}
if(tagStr.getBytes().length > 100){
int lengthSize = 100;
int count = 0;
while(true){
try{
  byte[] tmp = new byte[lengthSize];
  System.arraycopy(tagStr.getBytes(),0,tmp,0,lengthSize);
  String newWord = new String(tmp);
  if(StringUtils.isNotEmpty(newWord) && newWord.indexOf("?") != -1){
  throw new Exception();
  }
  splitArray[count] = new String(tmp);
  count++;
  System.out.println("擷取後 =" + (new String(tmp)) );
  tagStr = tagStr.replace(new String(tmp), "");
  if(tagStr.length() == 0){
  break;
  }else{
  lengthSize = 100;
  }
}catch(Exception e){
lengthSize =  lengthSize -1;
}
}
}else{
splitArray[0] = tagStr;
}
return splitArray;
}

2014年3月30日 星期日

從object取參數



public static int isNullSendAutoMail(Object obj,int count,Map argMap,String tableType){
Map calumnValues = new HashMap();
for (Field field : ReflectUtil.getFields(obj.getClass())){//obj.getClass().getDeclaredFields())
String valObject = "";
String attributeName = "";
attributeName = field.getName();
//取column的Value
String getterMethodName = "get" + attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1, attributeName.length());
Method m = null;
try {
m = obj.getClass().getMethod(getterMethodName);
valObject = (String) m.invoke(obj);
} catch (Exception e) {
}
//放到Map
calumnValues.put(attributeName,valObject );
}//end for