com.blocks.framework.utils.date.StringUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.blocks.framework.utils.date.StringUtil.java

Source

 /**
  * Copyright 2010 ZTEsoft Inc. All Rights Reserved.
  *
  * This software is the proprietary information of ZTEsoft Inc.
  * Use is subject to license terms.
  * 
  * $Tracker List
  * 
  * $TaskId: $ $Date: 9:24:36 AM (May 9, 2008) $comments: create 
  * $TaskId: $ $Date: 3:56:36 PM (SEP 13, 2010) $comments: upgrade jvm to jvm1.5 
  *  
  *  
  */
 package com.blocks.framework.utils.date;

 import java.io.*;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.MessageFormat;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

 /**
  * <p>
  * Title: pridigy
  * </p>
  * 
  * <p>
  * Description: 
  * </p>
  * 
  * <p>
  * Copyright: Copyright (c) 2004
  * </p>
  * 
  * <p>
  * Company: ztesoft
  * </p>
  * 
  * @author fan.zhenzhi
  * @version 1.0
  */
 public abstract class StringUtil {

     private StringUtil() {
     }

     /**
      * ???
      * 
      * @param val
      *            String ???
      * 
      * @param encoding
      *            String ??
      * 
      * @return String ???
      * 
      * @throws UnsupportedEncodingException
      */
     public static String encode(String val, String encoding) throws UnsupportedEncodingException {
         if (val == null) {
             return null;
         }
         return new String(val.getBytes(encoding));
     }

     /**
      * ??????
      * 
      * @param val
      *            String ???
      * 
      * @param formEncoding
      *            String ???
      * @param toEncoding
      *            String ??
      * @return String ???
      * 
      * @throws UnsupportedEncodingException
      */
     public static String encode(String val, String formEncoding, String toEncoding)
             throws UnsupportedEncodingException {
         if (val == null) {
             return null;
         }
         return new String(val.getBytes(formEncoding), toEncoding);
     }

     /**
      * ?,,?????, ??, ?JAVA?????.
      * 
      * @param columnName
      *            String ???
      * 
      * @return String ???
      * 
      */
     public static String getStandardStr(String columnName) {
         columnName = columnName.toLowerCase();
         StringBuffer sb = new StringBuffer();
         StringTokenizer token = new StringTokenizer(columnName, "_");
         int itoken = token.countTokens();
         for (int i = 0; i < itoken; i++) {
             if (i == 0) {
                 sb.append(token.nextToken());
             } else {
                 String temp = token.nextToken();
                 sb.append(temp.substring(0, 1).toUpperCase());
                 sb.append(temp.substring(1));
             }
         }
         return sb.toString();
     }

     /**
      * ??.null0?
      * 
      * @param val
      *            String ??
      * 
      * @return boolean true-, false-??
      * 
      */
     public static boolean isEmpty(String val) {
         if (val == null || val.length() == 0) {
             return true;
         }
         return false;
     }

     /**
      * ???.?val?val0
      * 
      * @param val
      *            String ??
      * 
      * @return boolean true-, false-??
      * 
      */
     public static boolean isNotEmpty(String val) {
         if (val == null || val.length() == 0) {
             return false;
         }

         return true;
     }

     /**
      * ??String
      * 
      * @param val
      *            Object
      * @return String
      */
     public static String toString(Object val) {
         if (val == null) {
             return "";
         }
         return val.toString();
     }

     /**
      * ??String
      * 
      * @param objs
      *            Object[]
      * @return String
      */
     public static String toString(Object[] objs) {
         if (objs != null && objs.length > 0) {
             StringBuffer buff = new StringBuffer();
             for (int i = 0; i < objs.length; i++) {
                 buff.append("\nItem[").append(i).append("]\n").append(objs[i]);
             }
             return buff.toString();
         } else {
             return "";
         }
     }

     /**
      * int??String
      * 
      * @param val
      *            int
      * @return String
      */
     public static String toString(int val) {
         return Integer.toString(val);
     }

     /**
      * float??String
      * 
      * @param val
      *            float
      * @return String
      */
     public static String toString(float val) {
         return Float.toString(val);
     }

     /**
      * double??String
      * 
      * @param val
      *            double
      * @return String
      */
     public static String toString(double val) {
         return Double.toString(val);
     }

     /**
      * long??String
      * 
      * @param val
      *            long
      * @return String
      */
     public static String toString(long val) {
         return Long.toString(val);
     }

     /**
      * short??String
      * 
      * @param val
      *            short
      * @return String
      */
     public static String toString(short val) {
         return Short.toString(val);
     }

     /**
      * boolean??String
      * 
      * @param val
      *            boolean
      * @return String
      */
     public static String toString(boolean val) {
         return Boolean.toString(val);
     }

     /**
      * Long??? zhang.nanyu added 2008-05-19
      * 
      * @param longArray Long[]
      * @return String
      */
     public static String toCommaString(Long[] longArray) {
         if (longArray == null || longArray.length <= 0) {
             return "";
         }
         StringBuffer buff = new StringBuffer();
         for (int i = 0; i < longArray.length; i++) {
             buff.append(longArray[i]);
             if (i != longArray.length - 1) {
                 buff.append(",");
             }
         }
         return buff.toString();
     }

     /**
      * ??String
      * 
      * @param objs
      *            Object[]
      * @param itemName
      *            String
      * @return String
      */
     public static String arrayToString(Object[] objs) {
         if (!ValidateUtil.validateNotEmpty(objs)) {
             return "";
         } else {
             int size = objs.length;
             StringBuffer buff = new StringBuffer();
             for (int i = 0; i < size; i++) {
                 buff.append(objs[i].toString()).append("\n");
             }
             return buff.toString();
         }
     }

     /**
      * ???ArrayList
      * 
      * @param ArrayList
      *            ??
      * 
      * @return String ??
      */

     public static String[] delRepeatData(ArrayList<String> al) {
         Set<String> set = new HashSet<String>(al);
         Object objs[] = set.toArray(new String[0]);
         return (String[]) objs;
     }

     /**
      * ???String
      * 
      * @param str
      *            String ??
      * 
      * @return String ??
      */
     public static String delRepeatData(String str) {
         ArrayList<String> al = new ArrayList<String>();
         StringBuilder dataBuf = new StringBuilder();
         if (str != null && str.length() >= 1) {
             StringTokenizer st = new StringTokenizer(str, ",");
             while (st.hasMoreTokens()) {
                 al.add(st.nextToken());
             }
             String singleDateArr[] = delRepeatData(al);
             if (singleDateArr != null) {
                 for (int i = 0; i < singleDateArr.length; i++) {
                     dataBuf.append(singleDateArr[i]);
                     if (i != singleDateArr.length - 1) {
                         dataBuf.append(",");
                     }
                 }
             }

         }
         return dataBuf.toString();
     }

     /**
      * ???String[]
      * 
      * @param String[]
      *            ??
      * 
      * @return String ??
      */

     public static String[] delRepeatData(String[] strArr) {
         ArrayList<String> al = new ArrayList<String>();

         if (strArr != null) {
             for (int i = 0; i < strArr.length; i++) {
                 al.add(strArr[i]);

             }
         }
         String singleDateArr[] = delRepeatData(al);

         return singleDateArr;
     }

     /**
      * ???Integer[]
      * 
      * @param Integer[]
      * 
      * @return String ??
      */

     public static Integer[] delRepeatData(Integer[] intArr) {
         ArrayList<Integer> al = new ArrayList<Integer>();

         if (intArr != null) {
             for (int i = 0; i < intArr.length; i++) {
                 al.add(intArr[i]);
             }
         }
         Set<Integer> set = new HashSet<Integer>(al);
         Object objs[] = set.toArray(new Integer[0]);
         return (Integer[]) objs;
     }

     /**
      * ???Long[]
      * 
      * @param Long[]
      * 
      * @return String ??
      */
     public static Long[] delRepeatData(Long[] intArr) {
         ArrayList<Long> al = new ArrayList<Long>();

         if (intArr != null) {
             for (int i = 0; i < intArr.length; i++) {
                 al.add(intArr[i]);
             }
         }
         Set<Long> set = new HashSet<Long>(al);
         return set.toArray(new Long[0]);
     }

     /**
      * add by chen yong 2007-2-5 samples: 1. Object[] arguments = { new
      * Integer(7), new Date(System.currentTimeMillis()), "a disturbance in the
      * Force" };
      * 
      * String result = MessageFormat.format( "At {1,time} on {1,date}, there was
      * {2} on planet {0,number,integer}.", arguments); output: At 13:57:11 on
      * 2007-2-5, there was a disturbance in the Force on planet 7. 2. Object[]
      * objs = {new Double(3.1415)}; String result = MessageFormat.format(
      * "{0,number,#.##}, {0,number,#.#}, {0}",objs); Output: 3.14, 3.1, 3.142
      * 
      * @param pattern
      *            message format pattern
      * @param arguments
      *            format arguments
      * @return the formatted string
      */
     public static String stringFormat(String pattern, Object[] arguments) {
         return MessageFormat.format(pattern, arguments);
     }

     /**
      * add by zhang.nanyu 2007-08-15
      * ???????15???
      * 
      * @param pattern
      *            message format pattern
      * @param arg1
      *            arguments
      * @return the formatted string
      */
     public static String stringFormat(String pattern) {

         return pattern;
     }

     public static String stringFormat(String pattern, Object arg1) {
         Object[] argList = new Object[] { arg1 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2) {
         Object[] argList = new Object[] { arg1, arg2 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3) {
         Object[] argList = new Object[] { arg1, arg2, arg3 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
             Object arg12) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
                 arg12 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
             Object arg12, Object arg13) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
                 arg13 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
             Object arg12, Object arg13, Object arg14) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
                 arg13, arg14 };
         return MessageFormat.format(pattern, argList);
     }

     public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
             Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
             Object arg12, Object arg13, Object arg14, Object arg15) {
         Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
                 arg13, arg14, arg15 };
         return MessageFormat.format(pattern, argList);
     }

     /**
      * ??
      * 
      * @author Lihaibin
      * @since 2007-03-22
      * @param ArrayList
      * @return String
      */
     public static String getStringDivideByCommaFromList(ArrayList array) {
         if ((array == null) || (array.size() == 0)) {
             return "";
         }
         // mod by chen.weizheng task CCB-3246 (ID:6368)
         // String[] bundle = (String[]) array.toArray(new String[array.size()]);
         // String ret = bundle[0];
         Object[] bundle = (Object[]) array.toArray(new Object[array.size()]);
         String ret = null;
         if (bundle[0] != null) {
             ret = bundle[0].toString();
         }

         for (int i = 1; i < bundle.length; i++) {
             ret += "," + bundle[i];
         }
         return ret;
     }

     /**
      * ? Unicode ?
      * 
      * 
      * 
      * 
      * 
      * @param s
      *            String
      * @param totalWidth
      *            int
      * @param paddingChar
      *            char
      * @return String
      * @throws BaseAppException
      */
     public static String padLeft(String s, int totalWidth, char paddingChar) {
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < totalWidth - s.length(); i++) {
             sb.append(paddingChar);
         }
         sb.append(s);
         return sb.toString();
     }

     /**
      * ?? Unicode ?
      * 
      * 
      * 
      * 
      * 
      * @param s
      *            String
      * @param totalWidth
      *            int
      * @param paddingChar
      *            char
      * @return String
      * @throws BaseAppException
      */
     public static String padRight(String s, int totalWidth, char paddingChar) {
         StringBuffer sb = new StringBuffer();
         sb.append(s);
         for (int i = 0; i < totalWidth - s.length(); i++) {
             sb.append(paddingChar);
         }
         return sb.toString();
     }

     public static boolean isNumeric(String str) {
         if (str == null)
             return false;

         for (int i = 0; i < str.length(); i++) {
             if (!Character.isDigit(str.charAt(i))) {
                 return false;
             }
         }
         return true;
     }

     /**
      * 
      * 
      * @param str
      *            String
      * @return String
      */
     public static String trim(String str) {
         return (str == null) ? str : str.trim();
     }

     /**
      * ?
      * 
      * @param paraSrc
      *            String
      * @param sepa
      *            String
      * @return Map sample : "a=b,c=d,..."
      */
     public static Map<String, String> splitPara(String paraSrc, String sepa) {
         if (paraSrc == null || paraSrc.trim().length() == 0) {
             return null;
         }

         LinkedHashMap<String, String> paraMap = new LinkedHashMap<String, String>();
         if (sepa == null || sepa.equals("")) { // ?,?

             sepa = ",";
         }

         /**
          * 
          */
         String[] paras = paraSrc.split(sepa);
         String tmpResult[] = null;
         for (int i = 0, j = 0; i < paras.length; i++) {
             tmpResult = paras[i].split("=");

             if (tmpResult.length >= 2) { // 2 a=b
                 paraMap.put(tmpResult[0].trim(), tmpResult[1]);
             } else if (tmpResult.length == 1) {
                 if (paras[i].indexOf("=") >= 0) { // 1 a=
                     paraMap.put(tmpResult[0].trim(), "");
                 } else { // 0 a
                     paraMap.put("TEXT." + j, paras[i]);
                     j++;
                 }
             }
         }

         return paraMap;
     }

/**
 * ?


 * 
 * 
 * @param str
 *            String
 * @return String
 */
public static String toDBCS(String str) {
   if (str == null) {
      return "";
   }

   StringBuffer sb = new StringBuffer();
   for (int i = 0, n = str.length(); i < n; i++) {
      int c = str.charAt(i);
      if ((c >= 'a') && (c <= 'z')) {
         c = (c + '?') - 'a';
      } else if ((c >= 'A') && (c <= 'Z')) {
         c = (c + '') - 'A';
      } else if ((c >= '0') && (c <= '9')) {
         c = (c + '?') - '0';
      }

      sb.append((char) c);
   }

   return sb.toString();
}

/**
 * ?


 * 
 * 
 * @param str
 *            String
 * @return String
 */
public static String toSBCS(String str) {
   if (str == null) {
      return "";
   }

   StringBuffer sb = new StringBuffer();
   for (int i = 0, n = str.length(); i < n; i++) {
      int c = str.charAt(i);
      if ((c >= '') && (c <= '')) { // A ..
         c = (c + 'A') - '';
      } else if ((c >= '?') && (c <= '')) { // a ..
         c = (c + 'a') - '?';
      } else if ((c >= '?') && (c <= '')) { // 0 ..
         c = (c + '0') - '?';
      } else if (c == '?') { // ??



         c = '"';
      } else if (c == '') {
         c = '"';
      } else if (c == '') { // ??



         c = '<';
      } else if (c == '') {
         c = '>';
      } else if (c == '') { // ??



         c = '\'';
      } else if (c == '') {
         c = '\'';
      } else if (c == '') { // ?
         c = ',';
      } else if (c == '') { // ?
         c = ';';
      } else if (c == '') {
         c = '.';
      } else if (c == '') {
         c = '&';
      }

      sb.append((char) c);
   }

   return sb.toString();
}

     /**
      * ?????
      * 
      * @param src
      *            String
      * @param pattern
      *            String
      * @return String[]
      */
     public static String[] findAll(String src, String pattern) {
         if (src == null) {
             return new String[0];
         }
         if (pattern == null) {
             return new String[0];
         }

         Pattern p = Pattern.compile(pattern);
         Matcher m = p.matcher(src);
         Collection<String> l = new ArrayList<String>();
         while (m.find()) {
             l.add(m.group());
         }

         return (String[]) l.toArray(new String[] {});
     }

     /**
      * ????
      * 
      * @param src
      *            String
      * @param pattern
      *            String
      * @param to
      *            String
      * @return String
      */
     public static String replaceAll(String src, String pattern, String to) {
         if (src == null) {
             return null;
         }
         if (pattern == null) {
             return src;
         }

         StringBuffer sb = new StringBuffer();
         Pattern p = Pattern.compile(pattern);
         Matcher m = p.matcher(src);

         int i = 1;
         while (m.find()) {
             // System.out.println("" + i + "?:" + m.group() +
             // " ?:" + m.start() + "-" + (m.end() - 1));
             m.appendReplacement(sb, to);
             i++;
         }
         m.appendTail(sb);
         // System.out.println("??:" + sb);
         return sb.toString();
     }

     /**
      * SQLIn??: (x,y,z)  ('x','y','z')
      * 
      * @param conditions
      *            String[]
      * @param isString
      *            boolean
      * @return String
      */
     public static final String getQryCondtion(String[] conditions, boolean isString) {
         if (conditions == null || conditions.length <= 0) {
             return null;
         }
         StringBuffer cond = new StringBuffer("(");
         for (int i = 0; i < conditions.length; i++) {
             if (isString) {
                 cond.append("'").append(conditions[i]).append("'");
             } else {
                 cond.append(conditions[i]);
             }
             cond.append(",");
         }
         cond.replace(cond.length() - 1, cond.length(), ")");

         return cond.toString();
     }

     /**
      * 
      * @param c
      *            Collection
      * @return String
      */
     public static String loadFromCollection(Collection c) {
         StringBuffer sb = new StringBuffer();
         Iterator it = c.iterator();
         while (it.hasNext()) {
             sb.append(it.next().toString());
         }
         return sb.toString();
     }

     /**
      * TEXT FILE ?, ?
        
        
      * 
      * 
      * @param filename
      *            String
      * @throws FileNotFoundException
      * @throws IOException
      * @return String
      */
     public static String loadFromFile(String filename) throws FileNotFoundException, IOException {
         StringBuffer sb = new StringBuffer();
         FileInputStream in = new FileInputStream(filename);
         byte[] buf = new byte[1024];

         try {
             while (true) {
                 int n = in.read(buf);
                 sb.append(new String(buf, 0, n));
                 if (n < 1024) {
                     break;
                 }
             }
         } catch (IOException ex) {
             throw ex;
         } finally {
             in.close();
         }

         return sb.toString();
     }

     /**
      * TEXT FILE ????
      * 
      * @param filename
      *            String
      * @throws FileNotFoundException
      * @throws IOException
      * @return String
      */
     public static String loadFromFile(String filename, String encoding) throws FileNotFoundException, IOException {
         StringBuffer sb = new StringBuffer();
         BufferedReader b = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));

         try {
             while (true) {
                 String s = b.readLine();
                 if (s != null) {
                     sb.append(s + "\r\n");
                 } else {
                     break;
                 }
             }
         } catch (IOException ex) {
             throw ex;
         } finally {
             b.close();
         }

         return sb.toString();
     }

     /**
      * URL ?
      * 
      * @param url
      *            String
      * @throws MalformedURLException
      * @throws IOException
      * @return String
      */
     public static String loadFromUrl(String url) throws MalformedURLException, IOException {
         StringBuffer sb = new StringBuffer();
         URL u = new URL(url);
         InputStream in = u.openStream();
         byte[] buf = new byte[1024];

         try {
             while (true) {
                 int n = in.read(buf);
                 sb.append(new String(buf, 0, n));
                 if (n < 1024) {
                     break;
                 }
             }
         } catch (IOException ex) {
             in.close();
             throw ex;
         } finally {
             in.close();
         }

         return sb.toString();
     }

     /**
      * ?"aa_a","a_","A"?"aa_a""a_"?"A" aAa
      * 
      * @param source
      * @param oldString
      * @param newString
      * @return
      */
     public static String replace(String source, String oldString, String newString) {
         StringBuffer output = new StringBuffer();
         int lengthOfSource = source.length();
         int lengthOfOld = oldString.length();
         int posStart;
         int pos;
         for (posStart = 0; (pos = source.indexOf(oldString, posStart)) >= 0; posStart = pos + lengthOfOld) {
             output.append(source.substring(posStart, pos));
             output.append(newString);
         }

         if (posStart < lengthOfSource) {
             output.append(source.substring(posStart));
         }
         return output.toString();
     }

     /**
      * 
      * @param name
      * @param split
      * @return
      */
     public static String secondSplit(String name, String split) {
         if (name == null || name.equals("")) {
             return "";
         }
         if (split == null || split.equals("")) {
             split = ".";
         }

         int index = name.indexOf(split);
         if (index >= 0) {
             return name.substring(index + split.length());
         }

         return name;
     }

     /**
      * return String basename
      * 
      * @param name
      *            String
      * @param split
      *            String
      * @return String com.ztesoft.ispp.ne --> ne
      */
     public static String pathname(String name, String split) {
         if (name == null || name.equals("")) {
             return "";
         }
         if (split == null || split.equals("")) {
             split = ".";
         }

         int index = name.lastIndexOf(split);
         if (index >= 0) {
             return name.substring(0, index);
         }

         return name;
     }

     /**
      * return String basename
      * 
      * @param name
      *            String
      * @param split
      *            String
      * @return String com.ztesoft.ispp.ne --> ne
      */
     public static String basename(String name, String split) {
         if (name == null || name.equals("")) {
             return "";
         }
         if (split == null || split.equals("")) {
             split = ".";
         }

         int index = name.lastIndexOf(split);
         if (index >= 0) {
             return name.substring(index + split.length());
         }

         return name;
     }

     /**
      * 
      * @param src
      *            String
      * @return String
      */
     public static String firstCharToUpperCase(String src) {
         if (src == null) {
             return null;
         }

         if (src.length() > 0) {
             src = src.substring(0, 1).toUpperCase() + src.substring(1);
         }

         return src;
     }

     /**
      * 
      * @param t
      * @return
      */
     public static String throwableToString(Throwable t) {
         StringBuffer sb = new StringBuffer();
         sb.append(t.getClass().getName());
         if (t.getMessage() != null) {
             ByteArrayOutputStream bo = new ByteArrayOutputStream();
             t.printStackTrace(new PrintStream(bo));
             sb.append(":\r\n\t" + bo.toString());
         }
         return sb.toString();
     }

     /**
      * long????strstr?
        
        
      *  long2StringForLen(30,"000000")
      *  000030
      * @param num
      * @param str
      * @return
      */
     public static String long2StringForLen(long num, String str) {
         int len = String.valueOf(num).length();
         if (len > str.length()) {
             return String.valueOf(num).substring(len - str.length(), len);
         } else {

             return str.substring(0, str.length() - len) + String.valueOf(num);
         }
     }

     /**
      * nullobject toString()
        
        
      * @param obj
      * @return
      */
     public static String objToString(Object obj) {
         return obj == null ? "" : obj.toString();
     }

     /**
       *  split?
        
       * @param line String
       * @param separator String
       * @return String[]
       */
     public static final String[] split(String line, String separator) {
         LinkedList<String> list = new LinkedList<String>();
         if (line != null) {
             int start = 0;
             int end = 0;
             int separatorLen = separator.length();
             while ((end = line.indexOf(separator, start)) >= 0) {
                 list.add(line.substring(start, end));
                 start = end + separatorLen;
             }
             if (start < line.length()) {
                 list.add(line.substring(start, line.length()));
             }
         }
         return (String[]) list.toArray(new String[list.size()]);
     }

     /**
      * ?
      * @param str 
        
      * @param len ?
      * @param elide ?
        
      * @return String
      */
     public static String splitString(String str, int len, String elide) {
         if (str == null) {
             return "";
         }
         byte[] strByte = str.getBytes();
         int strLen = strByte.length;
         int elideLen = (elide.trim().length() == 0) ? 0 : elide.getBytes().length;
         if (len >= strLen || len < 1) {
             return str;
         }
         if (len - elideLen > 0) {
             len = len - elideLen;
         }
         int count = 0;
         for (int i = 0; i < len; i++) {
             int value = (int) strByte[i];
             if (value < 0) {
                 count++;
             }
         }
         if (count % 2 != 0) {
             len = (len == 1) ? len + 1 : len - 1;

         }
         return new String(strByte, 0, len) + elide.trim();
     }

     /**
     * ???
     * 
     * @author Lihaibin
     * @since 2007-03-22
     * @param ArrayList
     * @return String
     */
     public static String getStringDivideByCommaFromList(Object[] inputList, boolean isNeedAddSingleQuote) {
         if ((inputList == null) || (inputList.length == 0)) {
             return "";
         }
         String ret = null;
         if (inputList[0] != null) {
             if (isNeedAddSingleQuote) {
                 ret = "'" + inputList[0].toString() + "'";
             } else {
                 ret = inputList[0].toString();
             }
         }

         for (int i = 1; i < inputList.length; i++) {

             if (isNeedAddSingleQuote) {
                 ret += "," + "'" + inputList[i].toString() + "'";
             } else {
                 ret += "," + inputList[i].toString();
             }
         }
         return ret;
     }

     /**
      * org.apache.commons.lang3.StringUtils?Thread.currentThread().getContextClassLoader() jni ??: .
      * StringUtils.capitalize(null)  = null
      * StringUtils.capitalize("")    = ""
      * StringUtils.capitalize("cat") = "Cat"
      * StringUtils.capitalize("cAt") = "CAt"
      * </pre>
      */
     public static String capitalize(String str) {
         int strLen;
         if (str == null || (strLen = str.length()) == 0) {
             return str;
         }
         return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
                 .toString();
     }
 }