自己常用的stringUtils

/*      */ import java.io.BufferedReader;
/*      */ import java.io.ByteArrayOutputStream;
/*      */ import java.io.File;
/*      */ import java.io.FileNotFoundException;
/*      */ import java.io.FileReader;
/*      */ import java.io.IOException;
/*      */ import java.io.InputStream;
/*      */ import java.io.PrintStream;
/*      */ import java.io.UnsupportedEncodingException;
/*      */ import java.text.DecimalFormat;
/*      */ import java.text.NumberFormat;
/*      */ import java.util.Currency;
/*      */ import java.util.HashSet;
/*      */ import java.util.Iterator;
/*      */ import java.util.Locale;
/*      */ import java.util.StringTokenizer;
/*      */ import java.util.regex.Matcher;
/*      */ import java.util.regex.Pattern;
/*      */ 
/*      */ public class StringUtils
/*      */ {
/*      */   public static String notNull(Object strObject)
/*      */   {
/*   33 */     return notNull(strObject, "");
/*      */   }
/*      */ 
/*      */   public static String notNull(Object strObject, String defaultValue)
/*      */   {
/*   43 */     if ((strObject == null) || ("".equals(strObject.toString().trim()))) {
/*   44 */       return defaultValue;
/*      */     }
/*   46 */     return strObject.toString();
/*      */   }
/*      */ 
/*      */   public static String notNull(String str)
/*      */   {
/*   56 */     return notNull(str, "");
/*      */   }
/*      */ 
/*      */   public static String notNull(String str, String defaultValue)
/*      */   {
/*   66 */     if ((str == null) || ("".equals(str.trim()))) {
/*   67 */       return defaultValue;
/*      */     }
/*   69 */     return str;
/*      */   }
/*      */ 
/*      */   public static String ifNull(Object s)
/*      */   {
/*   78 */     return ((s == null) ? "" : s.toString());
/*      */   }
/*      */ 
/*      */   public static String ifNull(Object s, String desc)
/*      */   {
/*   87 */     return ((s == null) ? desc : s.toString());
/*      */   }
/*      */ 
/*      */   public static boolean isBlank(String s)
/*      */   {
/*   97 */     return ((s == null) || ("".equals(s)));
/*      */   }
/*      */ 
/*      */   public static String fillStringBefore(String source, String fillSeperator, int length)
/*      */   {
/*  112 */     String dest = "";
/*  113 */     if (source == null) {
/*  114 */       source = "";
/*      */     }
/*  116 */     for (int i = 0; i < length - source.length(); ++i)
/*  117 */       dest = dest + fillSeperator;
/*  118 */     dest = dest + source;
/*  119 */     return dest;
/*      */   }
/*      */ 
/*      */   public static String inc(String source)
/*      */   {
/*  127 */     if (source == null) {
/*  128 */       return "0";
/*      */     }
/*  130 */     int length = source.length();
/*  131 */     long temp = Long.parseLong(source) + 1L;
/*  132 */     return fillStringBefore(String.valueOf(temp), "0", length);
/*      */   }
/*      */ 
/*      */   public static String sqlFilter(String content)
/*      */   {
/*  141 */     content = (content == null) ? "" : content;
/*  142 */     content = replace(content, "'", "''");
/*  143 */     return content;
/*      */   }
/*      */ 
/*      */   public static String filter(String content)
/*      */   {
/*  152 */     if (content == null) {
/*  153 */       return "";
/*      */     }
/*  155 */     content = (content == null) ? " " : content;
/*  156 */     content = replace(content, "<", "<");
/*  157 */     content = replace(content, ">", ">");
/*  158 */     content = replace(content, " ", " ");
/*  159 */     content = replace(content, "\n", "<BR>");
/*  160 */     return content;
/*      */   }
/*      */ 
/*      */   public static String filter(Object content)
/*      */   {
/*  169 */     return filter((String)content);
/*      */   }
/*      */ 
/*      */   public static String replace(String srcStr, String oldStr, String newStr)
/*      */   {
/*  180 */     return srcStr.replaceAll(oldStr, newStr);
/*      */   }
/*      */ 
/*      */   public static String replaceAll(String source, String parm1, String parm2)
/*      */   {
/*  191 */     if ((source == null) || (parm1 == null) || (parm2 == null) || (parm1.length() < 1)) {
/*  192 */       return source;
/*      */     }
/*  194 */     StringBuffer sReturn = new StringBuffer();
/*  195 */     StringTokenizer st = new StringTokenizer(source, parm1);
/*  196 */     int i = 0;
/*  197 */     while (st.hasMoreTokens()) {
/*  198 */       if (i > 0)
/*  199 */         sReturn.append(parm2);
/*      */       else {
/*  201 */         i = 1;
/*      */       }
/*  203 */       sReturn.append(st.nextToken());
/*      */     }
/*  205 */     return sReturn.toString();
/*      */   }
/*      */ 
/*      */   public static String parseInsertStr(String[][] data)
/*      */   {
/*  214 */     StringBuffer sb1 = new StringBuffer();
/*  215 */     sb1.append(" (");
/*  216 */     StringBuffer sb2 = new StringBuffer();
/*  217 */     sb2.append(" values(");
/*  218 */     for (int i = 0; i < data.length; ++i) {
/*  219 */       sb1.append(data[i][0]);
/*  220 */       switch (data[i][2].charAt(0))
/*      */       {
/*      */       case '1':
/*  222 */         sb2.append("'" + data[i][1] + "'");
/*  223 */         break;
/*      */       case '2':
/*  225 */         sb2.append(data[i][1]);
/*      */       }
/*      */ 
/*  228 */       if (i < data.length - 1) {
/*  229 */         sb1.append(",");
/*  230 */         sb2.append(",");
/*      */       }
/*      */       else {
/*  233 */         sb1.append(")");
/*  234 */         sb2.append(")");
/*      */       }
/*      */     }
/*  237 */     sb1.append(sb2.toString());
/*  238 */     return sb1.toString();
/*      */   }
/*      */ 
/*      */   public static String parseUpdateStr(String[][] data)
/*      */   {
/*  247 */     StringBuffer sb1 = new StringBuffer();
/*  248 */     sb1.append(" ");
/*  249 */     for (int i = 0; i < data.length; ++i) {
/*  250 */       sb1.append(data[i][0]);
/*  251 */       sb1.append("=");
/*  252 */       switch (data[i][2].charAt(0))
/*      */       {
/*      */       case '1':
/*  254 */         sb1.append("'" + data[i][1] + "'");
/*  255 */         break;
/*      */       case '2':
/*  257 */         sb1.append(data[i][1]);
/*      */       }
/*      */ 
/*  260 */       if (i < data.length - 1) {
/*  261 */         sb1.append(",");
/*      */       }
/*      */     }
/*  264 */     return sb1.toString();
/*      */   }
/*      */ 
/*      */   public static final byte[] base64Encode(byte[] byteData)
/*      */   {
/*  273 */     if (byteData == null) {
/*  274 */       return null;
/*      */     }
/*      */ 
/*  277 */     byte[] byteDest = new byte[(byteData.length + 2) / 3 * 4];
/*      */ 
/*  279 */     int iSrcIdx = 0; for (int iDestIdx = 0; iSrcIdx < byteData.length - 2; iSrcIdx += 3) {
/*  280 */       byteDest[(iDestIdx++)] = (byte)(byteData[iSrcIdx] >>> 2 & 0x3F);
/*  281 */       byteDest[(iDestIdx++)] = (byte)(byteData[(iSrcIdx + 1)] >>> 4 & 0xF | byteData[iSrcIdx] << 4 & 0x3F);
/*  282 */       byteDest[(iDestIdx++)] = (byte)(byteData[(iSrcIdx + 2)] >>> 6 & 0x3 | byteData[(iSrcIdx + 1)] << 2 & 0x3F);
/*  283 */       byteDest[(iDestIdx++)] = (byte)(byteData[(iSrcIdx + 2)] & 0x3F);
/*      */     }
/*      */ 
/*  286 */     if (iSrcIdx < byteData.length) {
/*  287 */       byteDest[(iDestIdx++)] = (byte)(byteData[iSrcIdx] >>> 2 & 0x3F);
/*  288 */       if (iSrcIdx < byteData.length - 1) {
/*  289 */         byteDest[(iDestIdx++)] = (byte)(byteData[(iSrcIdx + 1)] >>> 4 & 0xF | byteData[iSrcIdx] << 4 & 0x3F);
/*  290 */         byteDest[(iDestIdx++)] = (byte)(byteData[(iSrcIdx + 1)] << 2 & 0x3F);
/*      */       } else {
/*  292 */         byteDest[(iDestIdx++)] = (byte)(byteData[iSrcIdx] << 4 & 0x3F);
/*      */       }
/*      */     }
/*  295 */     for (iSrcIdx = 0; iSrcIdx < iDestIdx; ++iSrcIdx) {
/*  296 */       if (byteDest[iSrcIdx] < 26)
/*  297 */         byteDest[iSrcIdx] = (byte)(byteDest[iSrcIdx] + 65);
/*  298 */       else if (byteDest[iSrcIdx] < 52)
/*  299 */         byteDest[iSrcIdx] = (byte)(byteDest[iSrcIdx] + 97 - 26);
/*  300 */       else if (byteDest[iSrcIdx] < 62)
/*  301 */         byteDest[iSrcIdx] = (byte)(byteDest[iSrcIdx] + 48 - 52);
/*  302 */       else if (byteDest[iSrcIdx] < 63)
/*  303 */         byteDest[iSrcIdx] = 43;
/*      */       else {
/*  305 */         byteDest[iSrcIdx] = 47;
/*      */       }
/*      */     }
/*  308 */     for (; iSrcIdx < byteDest.length; ++iSrcIdx) {
/*  309 */       byteDest[iSrcIdx] = 61;
/*      */     }
/*  311 */     return byteDest;
/*      */   }
/*      */ 
/*      */   public static final String base64Encode(String strInput)
/*      */   {
/*  320 */     if (strInput == null)
/*  321 */       return null;
/*  322 */     return base64Encode(strInput, "GB2312");
/*      */   }
/*      */ 
/*      */   public static final String base64Encode(String strInput, String charSet)
/*      */   {
/*  332 */     if (strInput == null)
/*  333 */       return null;
/*  334 */     String strOutput = null;
/*  335 */     byte[] byteData = new byte[strInput.length()];
/*      */     try
/*      */     {
/*  338 */       byteData = strInput.getBytes(charSet);
/*  339 */       strOutput = new String(base64Encode(byteData), charSet);
/*      */     }
/*      */     catch (UnsupportedEncodingException e) {
/*  342 */       return null;
/*      */     }
/*  344 */     return strOutput;
/*      */   }
/*      */ 
/*      */   public static final String base64Encode(InputStream in, String charSet)
/*      */   {
/*      */     try
/*      */     {
/*  359 */       byte[] buff = new byte[1024];
/*  360 */       ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
/*      */       int c;
/*  361 */       while ((c = in.read(buff, 0, 1024)) != -1)
/*      */       {
/*      */         int c;
/*  362 */         out.write(buff, 0, c);
/*      */       }
/*      */ 
/*  367 */       in.close();
/*  368 */       out.flush();
/*  369 */       byte[] tmp2 = base64Encode(out.toByteArray());
/*  370 */       out.close();
/*  371 */       return new String(tmp2, charSet); } catch (IOException e) {
/*      */     }
/*  373 */     return "";
/*      */   }
/*      */ 
/*      */   public static String encodeBase64(byte[] abyte0)
/*      */   {
/*  383 */     int l = abyte0.length;
/*  384 */     StringBuffer stringbuffer = new StringBuffer((l / 3 + 1) * 4);
/*  385 */     for (int i1 = 0; i1 < l; ++i1) {
/*  386 */       int i = abyte0[i1] >> 2 & 0x3F;
/*  387 */       stringbuffer.append(
/*  388 */         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  389 */         .charAt(i));
/*  390 */       i = abyte0[i1] << 4 & 0x3F;
/*  391 */       if (++i1 < l) {
/*  392 */         i |= abyte0[i1] >> 4 & 0xF;
/*      */       }
/*  394 */       stringbuffer.append(
/*  395 */         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  396 */         .charAt(i));
/*  397 */       if (i1 < l) {
/*  398 */         int j = abyte0[i1] << 2 & 0x3F;
/*  399 */         if (++i1 < l) {
/*  400 */           j |= abyte0[i1] >> 6 & 0x3;
/*      */         }
/*  402 */         stringbuffer.append(
/*  403 */           "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  404 */           .charAt(j));
/*      */       }
/*      */       else {
/*  407 */         ++i1;
/*  408 */         stringbuffer.append('=');
/*      */       }
/*  410 */       if (i1 < l) {
/*  411 */         int k = abyte0[i1] & 0x3F;
/*  412 */         stringbuffer.append(
/*  413 */           "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  414 */           .charAt(k));
/*      */       }
/*      */       else {
/*  417 */         stringbuffer.append('=');
/*      */       }
/*      */     }
/*  420 */     return stringbuffer.toString();
/*      */   }
/*      */ 
/*      */   public static String encodeBase64(String s)
/*      */   {
/*  429 */     return encodeBase64(s.getBytes());
/*      */   }
/*      */ 
/*      */   public static String decodeBase64(byte[] abyte0)
/*      */   {
/*  438 */     int k = abyte0.length;
/*  439 */     StringBuffer stringbuffer = new StringBuffer(k * 3 / 4);
/*  440 */     for (int l = 0; l < k; ++l) {
/*  441 */       int i = 
/*  442 */         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  443 */         .indexOf(abyte0[l]);
/*  444 */       ++l;
/*  445 */       int j = 
/*  446 */         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  447 */         .indexOf(abyte0[l]);
/*  448 */       i = i << 2 | j >> 4 & 0x3;
/*  449 */       stringbuffer.append((char)i);
/*  450 */       if (++l < k) {
/*  451 */         i = abyte0[l];
/*  452 */         if (i == 61) {
/*      */           break;
/*      */         }
/*  455 */         i = 
/*  456 */           "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  457 */           .indexOf((char)i);
/*  458 */         j = j << 4 & 0xF0 | i >> 2 & 0xF;
/*  459 */         stringbuffer.append((char)j);
/*      */       }
/*  461 */       if (++l >= k) {
/*      */         continue;
/*      */       }
/*  464 */       j = abyte0[l];
/*  465 */       if (j == 61) {
/*      */         break;
/*      */       }
/*  468 */       j = 
/*  469 */         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/*  470 */         .indexOf((char)j);
/*  471 */       i = i << 6 & 0xC0 | j;
/*  472 */       stringbuffer.append((char)i);
/*      */     }
/*  474 */     return stringbuffer.toString();
/*      */   }
/*      */ 
/*      */   public static String decodeBase64(String s)
/*      */   {
/*  483 */     return decodeBase64(s.getBytes());
/*      */   }
/*      */ 
/*      */   public static String GB2312_ISO8859_1(String src)
/*      */   {
/*      */     try
/*      */     {
/*  493 */       return new String(src.getBytes("GB2312"), "ISO8859_1");
/*      */     }
/*      */     catch (Exception ex) {
/*  496 */       ToftLogger.error(ex.getMessage()); }
/*  497 */     return null;
/*      */   }
/*      */ 
/*      */   public static String ISO8859_1_GB2312(String src)
/*      */   {
/*      */     try
/*      */     {
/*  508 */       return new String(src.getBytes("ISO8859_1"), "GB2312");
/*      */     }
/*      */     catch (Exception ex) {
/*  511 */       ToftLogger.error(ex.getMessage()); }
/*  512 */     return null;
/*      */   }
/*      */ 
/*      */   public static String GBK_ISO8859_1(String src)
/*      */   {
/*      */     try
/*      */     {
/*  523 */       return new String(src.getBytes("GBK"), "ISO8859_1");
/*      */     }
/*      */     catch (Exception ex) {
/*  526 */       ToftLogger.error(ex.getMessage()); }
/*  527 */     return null;
/*      */   }
/*      */ 
/*      */   public static String ISO8859_1_GBK(String src)
/*      */   {
/*      */     try
/*      */     {
/*  538 */       return new String(src.getBytes("ISO8859_1"), "GBK");
/*      */     }
/*      */     catch (Exception ex) {
/*  541 */       ToftLogger.error(ex.getMessage()); }
/*  542 */     return null;
/*      */   }
/*      */ 
/*      */   public static String doubleToCurrency(double f, String moneyUnit, String digit)
/*      */   {
/*  556 */     NumberFormat nf = NumberFormat.getIntegerInstance();
/*  557 */     if (moneyUnit == null) {
/*  558 */       return "空";
/*      */     }
/*  560 */     if ((moneyUnit.equals("万元")) || (moneyUnit.equals("2"))) {
/*  561 */       f /= 10000.0D;
/*      */     }
/*  563 */     if ((moneyUnit.equals("亿元")) || (moneyUnit.equals("3"))) {
/*  564 */       f /= 100000000.0D;
/*      */     }
/*  566 */     if (digit == null) {
/*  567 */       nf.setMinimumFractionDigits(2);
/*  568 */       nf.setMaximumFractionDigits(2);
/*      */     }
/*      */     else {
/*  571 */       nf.setMinimumFractionDigits(Integer.parseInt(digit));
/*  572 */       nf.setMaximumFractionDigits(Integer.parseInt(digit));
/*      */     }
/*  574 */     return nf.format(f);
/*      */   }
/*      */ 
/*      */   public static double currencyToDouble(double f, String moneyUnit, String digit)
/*      */   {
/*  586 */     return stringToDouble(replace(doubleToCurrency(f, moneyUnit, digit), 
/*  587 */       ",", 
/*  588 */       ""));
/*      */   }
/*      */ 
/*      */   public static String stringToCurrency(String ff, String moneyUnit, String digit)
/*      */   {
/*  600 */     double f = stringToDouble(ff);
/*  601 */     return doubleToCurrency(f, moneyUnit, digit);
/*      */   }
/*      */ 
/*      */   public static String stringToCurrency(String ff, String moneyUnit, String digit, boolean zeroFlag)
/*      */   {
/*  612 */     if ((zeroFlag) && ((
/*  613 */       (ff == null) || ("".equals(ff)) || (Double.parseDouble(ff.toString()) == 0.0D)))) {
/*  614 */       return "0.00";
/*      */     }
/*      */ 
/*  617 */     return stringToCurrency(ff, "1", "2");
/*      */   }
/*      */ 
/*      */   public static String doubleToCurrency1(double f, Locale l)
/*      */   {
/*  628 */     NumberFormat nf = (l == null) ? NumberFormat.getCurrencyInstance() : 
/*  629 */       NumberFormat.getCurrencyInstance(l);
/*  630 */     return nf.format(f);
/*      */   }
/*      */ 
/*      */   public static String doubleToCurrency2(double f, Locale l)
/*      */   {
/*  642 */     NumberFormat nf = (l == null) ? NumberFormat.getCurrencyInstance() : 
/*  643 */       NumberFormat.getCurrencyInstance(l);
/*  644 */     String temp = nf.format(f);
/*  645 */     int i = temp.indexOf(nf.getCurrency().getSymbol());
/*  646 */     if (i > 0) {
/*  647 */       return temp.substring(0, i) + temp.substring(i + 1);
/*      */     }
/*      */ 
/*  650 */     return temp.substring(1);
/*      */   }
/*      */ 
/*      */   public static String doubleToCurrency3(double f, Locale l)
/*      */   {
/*  661 */     String currency = doubleToCurrency2(f, l);
/*  662 */     return replace(currency, ",", "");
/*      */   }
/*      */ 
/*      */   public static String floatToCurrency1(float f, Locale l)
/*      */   {
/*  673 */     NumberFormat nf = (l == null) ? NumberFormat.getCurrencyInstance() : 
/*  674 */       NumberFormat.getCurrencyInstance(l);
/*  675 */     return nf.format(f);
/*      */   }
/*      */ 
/*      */   public static String floatToCurrency3(float f, Locale l)
/*      */   {
/*  686 */     NumberFormat nf = (l == null) ? NumberFormat.getCurrencyInstance() : 
/*  687 */       NumberFormat.getCurrencyInstance(l);
/*  688 */     String currency = nf.format(f).substring(1);
/*  689 */     return replace(currency, ",", "");
/*      */   }
/*      */ 
/*      */   public static String floatToCurrency2(float f, Locale l)
/*      */   {
/*  702 */     NumberFormat nf = (l == null) ? NumberFormat.getCurrencyInstance() : 
/*  703 */       NumberFormat.getCurrencyInstance(l);
/*  704 */     return nf.format(f).substring(1);
/*      */   }
/*      */ 
/*      */   public static String stringToCurrency1(String str, Locale l)
/*      */   {
/*  715 */     if ((str == null) || (str.equals(""))) {
/*  716 */       return "";
/*      */     }
/*      */ 
/*  719 */     double f = 0.0D;
/*      */     try {
/*  721 */       f = Double.parseDouble(str);
/*      */     }
/*      */     catch (Exception ex) {
/*  724 */       return "";
/*      */     }
/*      */ 
/*  727 */     return doubleToCurrency1(f, l);
/*      */   }
/*      */ 
/*      */   public static String stringToCurrency3(String str, Locale l)
/*      */   {
/*  740 */     if ((str == null) || (str.equals(""))) {
/*  741 */       return "";
/*      */     }
/*      */     double f;
/*      */     try
/*      */     {
/*  746 */       f = Double.parseDouble(str);
/*      */     }
/*      */     catch (Exception ex) {
/*  749 */       return "";
/*      */     }
/*      */     double f;
/*  752 */     return doubleToCurrency3(f, l);
/*      */   }
/*      */ 
/*      */   public static String stringToCurrency2(String str, Locale l)
/*      */   {
/*  765 */     if ((str == null) || (str.equals(""))) {
/*  766 */       return "";
/*      */     }
/*      */     double f;
/*      */     try
/*      */     {
/*  771 */       f = Double.parseDouble(str);
/*      */     }
/*      */     catch (Exception ex) {
/*  774 */       return "";
/*      */     }
/*      */     double f;
/*  777 */     return doubleToCurrency2(f, l);
/*      */   }
/*      */ 
/*      */   public static String upperCaseFirstChar(Object obj)
/*      */   {
/*  787 */     String str = (String)obj;
/*  788 */     if ((str == null) || (str.equals(""))) {
/*  789 */       return "";
/*      */     }
/*  791 */     char[] c = str.toCharArray();
/*  792 */     c[0] = Character.toUpperCase(c[0]);
/*  793 */     return new String(c);
/*      */   }
/*      */ 
/*      */   public static String toCapital(String str_money)
/*      */   {
/*  803 */     String str1 = "分角元拾佰仟万拾佰仟亿拾佰仟兆拾佰仟亿拾";
/*  804 */     String str2 = "零壹贰叁肆伍陆柒捌玖";
/*  805 */     String str3 = new String();
/*      */     try
/*      */     {
/*  808 */       int i = str_money.indexOf(46);
/*  809 */       int len = str_money.length();
/*      */       int b;
/*  810 */       if (i == -1) {
/*  811 */         int b = 2;
/*  812 */         str3 = "整";
/*      */       }
/*  814 */       else if (str_money.charAt(i + 2) == '0') {
/*  815 */         int b = 1;
/*  816 */         str_money = str_money.substring(0, i) + 
/*  817 */           str_money.substring(i + 1);
/*  818 */         len = i + 1;
/*      */       }
/*      */       else {
/*  821 */         b = 0;
/*  822 */         str_money = str_money.substring(0, i) + 
/*  823 */           str_money.substring(i + 1, i + 3);
/*  824 */         len = i + 2;
/*      */       }
/*      */ 
/*  827 */       for (i = len - 1; i >= 0; --i) {
/*  828 */         int j = str_money.charAt(i) - '0';
/*  829 */         int m = len - i - 1 + b;
/*  830 */         if (j != 0) {
/*  831 */           str3 = str2.substring(j, j + 1) + str1.substring(m, m + 1) + 
/*  832 */             str3;
/*      */         }
/*  834 */         else if ((m == 14) || (m == 10) || (m == 6) || (m == 2)) {
/*  835 */           str3 = str1.substring(m, m + 1) + str3;
/*      */         }
/*      */         else {
/*  838 */           String tmp_str = str3.substring(0, 1);
/*  839 */           if ((tmp_str.equals("零")) && 
/*  840 */             (!(tmp_str.equals("万"))) && 
/*  841 */             (!(tmp_str.equals("兆"))) && 
/*  842 */             (!(tmp_str.equals("亿"))) && 
/*  843 */             (!(tmp_str.equals("元")))) continue;
/*  844 */           str3 = "零" + str3;
/*      */         }
/*      */       }
/*      */     }
/*      */     catch (StringIndexOutOfBoundsException localStringIndexOutOfBoundsException)
/*      */     {
/*      */     }
/*  851 */     return str3;
/*      */   }
/*      */ 
/*      */   public static String formatNumber(String inFormStr, int type)
/*      */   {
/*  861 */     String outFormStr = "";
/*      */ 
/*  863 */     if ((inFormStr == null) || (inFormStr.trim().equals(""))) {
/*  864 */       return "";
/*      */     }
/*      */     try
/*      */     {
/*  868 */       if (type == 1) {
/*  869 */         DecimalFormat df = new DecimalFormat("###,###,###,###");
/*      */ 
/*  871 */         outFormStr = df.format(df.parse(String.valueOf(inFormStr))); break label154:
/*      */       }
/*      */ 
/*  874 */       if (type == 2) {
/*  875 */         DecimalFormat df = new DecimalFormat("###,###,###,##0.00");
/*  876 */         outFormStr = df.format(df.parse(String.valueOf(inFormStr))); break label154:
/*      */       }
/*      */ 
/*  879 */       if (type == 3) {
/*  880 */         DecimalFormat df = new DecimalFormat("###,###,###,##0.#");
/*  881 */         outFormStr = df.format(df.parse(String.valueOf(inFormStr))); break label154:
/*      */       }
/*      */ 
/*  884 */       if (type == 4) {
/*  885 */         DecimalFormat df = new DecimalFormat("####.##");
/*  886 */         outFormStr = df.format(df.parse(String.valueOf(inFormStr)));
/*      */       }
/*      */     }
/*      */     catch (Exception e)
/*      */     {
/*  891 */       return "";
/*      */     }
/*  893 */     label154: return outFormStr;
/*      */   }
/*      */ 
/*      */   public static String formatNumber(int inFormint, int type)
/*      */   {
/*  903 */     String ret = formatNumber(String.valueOf(inFormint), type);
/*      */ 
/*  905 */     return ret;
/*      */   }
/*      */ 
/*      */   public static String formatNumber(long inFormint, int type)
/*      */   {
/*  915 */     String ret = formatNumber(String.valueOf(inFormint), type);
/*      */ 
/*  917 */     return ret;
/*      */   }
/*      */ 
/*      */   public static String formatNumber(float inFormint, int type)
/*      */   {
/*  927 */     String ret = formatNumber(String.valueOf(inFormint), type);
/*  928 */     return ret;
/*      */   }
/*      */ 
/*      */   public static String formatNumber(double inFormint, int type)
/*      */   {
/*  938 */     String ret = formatNumber(String.valueOf(inFormint), type);
/*  939 */     return ret;
/*      */   }
/*      */ 
/*      */   public static double stringToDouble(String strDouble)
/*      */   {
/*  948 */     if ((strDouble == null) || (strDouble.equals(""))) {
/*  949 */       return 0.0D;
/*      */     }
/*  951 */     return Double.parseDouble(strDouble);
/*      */   }
/*      */ 
/*      */   public static float stringToFloat(String strFloat)
/*      */   {
/*  960 */     if ((strFloat == null) || (strFloat.equals(""))) {
/*  961 */       return 0.0F;
/*      */     }
/*  963 */     return Float.parseFloat(strFloat);
/*      */   }
/*      */ 
/*      */   public static String readIni(String funcNo, String path)
/*      */   {
/*  977 */     String fileStr = "";
/*  978 */     String FullFilename = path + "\\ini\\";
/*  979 */     FullFilename = FullFilename + funcNo + ".ini";
/*      */     try
/*      */     {
/*  982 */       File objFile = new File(FullFilename);
/*  983 */       FileReader objFileReader = new FileReader(objFile);
/*  984 */       BufferedReader objBufferedReader = new BufferedReader(objFileReader);
/*      */       String ss;
/*  985 */       while ((ss = objBufferedReader.readLine()) != null)
/*      */       {
/*      */         String ss;
/*  986 */         fileStr = fileStr + ss + "\\r\\n";
/*      */       }
/*      */     }
/*      */     catch (FileNotFoundException e) {
/*  990 */       ToftLogger.error(e.getMessage());
/*      */     }
/*      */     catch (IOException e) {
/*  993 */       ToftLogger.error(e.getMessage());
/*      */     }
/*  995 */     return fileStr;
/*      */   }
/*      */ 
/*      */   public static String makeRightConditionStr(HashSet set, String column)
/*      */   {
/* 1005 */     if (set.contains("*")) {
/* 1006 */       return "";
/*      */     }
/* 1008 */     if ((set == null) || (set.size() == 0)) {
/* 1009 */       return column + " in ('')";
/*      */     }
/* 1011 */     if ((set != null) && (set.size() > 0)) {
/* 1012 */       Iterator it = set.iterator();
/* 1013 */       String temp = "";
/* 1014 */       while (it.hasNext()) {
/* 1015 */         String temp1 = (String)it.next();
/* 1016 */         temp = temp + "'" + temp1 + "',";
/*      */       }
/* 1018 */       temp = temp.substring(0, temp.length() - 1);
/* 1019 */       return column + " in (" + temp + ")";
/*      */     }
/*      */ 
/* 1022 */     return "";
/*      */   }
/*      */ 
/*      */   public static String makeRightConditionS(HashSet set, String column)
/*      */   {
/* 1035 */     if (set.contains("*")) {
/* 1036 */       return "";
/*      */     }
/* 1038 */     if ((set == null) || (set.size() == 0)) {
/* 1039 */       return " AND " + column + " IN ('')";
/*      */     }
/* 1041 */     if ((set != null) && (set.size() > 0)) {
/* 1042 */       Iterator it = set.iterator();
/* 1043 */       String temp = "";
/* 1044 */       while (it.hasNext()) {
/* 1045 */         String temp1 = (String)it.next();
/* 1046 */         temp = temp + "'" + temp1 + "',";
/*      */       }
/* 1048 */       temp = temp.substring(0, temp.length() - 1);
/* 1049 */       return " AND " + column + " IN (" + temp + ")";
/*      */     }
/*      */ 
/* 1052 */     return "";
/*      */   }
/*      */ 
/*      */   public static double interceptDigitToDouble(String source, NumberFormat nf, int digit)
/*      */   {
/* 1067 */     if (Pattern.compile("^(-?\\d*)(\\.\\d+)?{1}quot;).matcher(source).matches()) {
/* 1068 */       return interceptDigitToDouble(Double.parseDouble(source), nf, digit);
/*      */     }
/*      */ 
/* 1071 */     throw new IllegalArgumentException("传入的字符串不是数字!");
/*      */   }
/*      */ 
/*      */   public static String interceptDigitToString(String source, NumberFormat nf, int digit)
/*      */   {
/* 1086 */     if (Pattern.compile("^(-?\\d*)(\\.\\d+)?{1}quot;).matcher(source).matches()) {
/* 1087 */       return interceptDigitToString(Double.parseDouble(source), nf, digit);
/*      */     }
/*      */ 
/* 1090 */     throw new IllegalArgumentException("传入的字符串不是数字!");
/*      */   }
/*      */ 
/*      */   public static double interceptDigitToDouble(double source, NumberFormat nf, int digit)
/*      */   {
/* 1105 */     nf.setMaximumFractionDigits(digit);
/* 1106 */     nf.setMinimumFractionDigits(digit);
/* 1107 */     return Double.parseDouble(nf.format(source).replaceAll(",", ""));
/*      */   }
/*      */ 
/*      */   public static String interceptDigitToString(double source, NumberFormat nf, int digit)
/*      */   {
/* 1119 */     nf.setMaximumFractionDigits(digit);
/* 1120 */     nf.setMinimumFractionDigits(digit);
/* 1121 */     return nf.format(source);
/*      */   }
/*      */ 
/*      */   public static byte[] readBytesFromInputStream(InputStream is)
/*      */     throws IOException
/*      */   {
/* 1131 */     byte[] data = (byte[])null;
/* 1132 */     if (is != null) {
/* 1133 */       ByteArrayOutputStream os = null;
/*      */       try {
/* 1135 */         os = new ByteArrayOutputStream(256);
/* 1136 */         byte[] buf = new byte[256];
/*      */         while (true) {
/* 1138 */           int bytes = is.read(buf);
/* 1139 */           if (bytes < 0) break;
/* 1140 */           if (bytes <= 0) continue; os.write(buf, 0, bytes);
/*      */         }
/* 1142 */         data = os.toByteArray();
/*      */       } finally {
/*      */         try {
/* 1145 */           if (os != null) os.close();
/*      */         } catch (Exception e) {
/* 1147 */           ToftLogger.error(e.getMessage());
/*      */         }
/*      */       }
/*      */     }
/* 1151 */     return data;
/*      */   }
/*      */ 
/*      */   public static String cipher(String psPass)
/*      */     throws Exception
/*      */   {
/* 1162 */     return makeDarkPass(psPass);
/*      */   }
/*      */ 
/*      */   public static String decipher(String psPass)
/*      */     throws Exception
/*      */   {
/* 1170 */     return getClearPass(psPass);
/*      */   }
/*      */ 
/*      */   private static String getPass(String psPass)
/*      */     throws Exception
/*      */   {
/* 1185 */     psPass = psPass.trim();
/* 1186 */     if (psPass.length() < 3) {
/* 1187 */       throw new Exception("密码长度必须大于等于3");
/*      */     }
/* 1189 */     if (psPass.length() > 30) {
/* 1190 */       throw new Exception("密码长度必须小于等于30");
/*      */     }
/* 1192 */     int viTemp = psPass.charAt(0);
/* 1193 */     int viAscSum = 0;
/* 1194 */     for (int j = 0; j < psPass.length(); ++j) {
/* 1195 */       char vcChar = psPass.substring(j, j + 1).charAt(0);
/* 1196 */       viTemp = vcChar;
/* 1197 */       viAscSum += viTemp;
/*      */     }
/* 1199 */     int viSumMod = viAscSum % 26;
/* 1200 */     int viMaxMod = viSumMod;
/* 1201 */     String vsModStr = "";
/* 1202 */     String vsDevStr = "";
/* 1203 */     for (int k = 0; k < psPass.length(); ++k) {
/* 1204 */       char vcChar = psPass.substring(k, k + 1).charAt(0);
/* 1205 */       viTemp = vcChar + viSumMod;
/* 1206 */       int viDev = viTemp / 26;
/* 1207 */       int viMod = viTemp - (viDev * 26);
/* 1208 */       if (viDev > viMaxMod) {
/* 1209 */         viMaxMod = viDev;
/*      */       }
/* 1211 */       vsModStr = vsModStr + "," + (char)(viMod + 97);
/* 1212 */       vsDevStr = vsDevStr + "," + String.valueOf(viDev);
/*      */     }
/* 1214 */     vsModStr = vsModStr.substring(1);
/* 1215 */     vsDevStr = vsDevStr.substring(1);
/* 1216 */     String vsTemp = "";
/* 1217 */     StringTokenizer st = new StringTokenizer(vsDevStr, 
/* 1218 */       ",");
/*      */     do {
/* 1220 */       char vcChar = st.nextToken().charAt(0);
/* 1221 */       viTemp = Integer.parseInt(String.valueOf(vcChar));
/* 1222 */       vsTemp = vsTemp + "," + (char)viTemp;
/*      */     }
/* 1219 */     while (
/* 1224 */       st.hasMoreTokens());
/* 1225 */     vsDevStr = vsTemp.substring(1);
/*      */ 
/* 1227 */     psPass = "";
/* 1228 */     int i = 0;
/* 1229 */     StringTokenizer st2 = new StringTokenizer(vsDevStr, 
/* 1230 */       ",");
/* 1231 */     StringTokenizer st3 = new StringTokenizer(vsModStr, 
/* 1232 */       ",");
/*      */     do {
/* 1234 */       ++i;
/* 1235 */       if (i % 2 == 1) {
/* 1236 */         psPass = st2.nextToken() + st3.nextToken() + psPass;
/*      */       }
/*      */       else {
/* 1239 */         psPass = st3.nextToken() + st2.nextToken() + psPass;
/*      */       }
/*      */     }
/* 1242 */     while ((st2.hasMoreTokens()) && (
/* 1242 */       st3.hasMoreTokens()));
/* 1243 */     return psPass;
/*      */   }
/*      */ 
/*      */   private static String getClearPass(String pass)
/*      */   {
/* 1254 */     String vsPass = "";
/* 1255 */     char vcBegin = pass.charAt(0);
/* 1256 */     char vcEnd = pass.charAt(pass.length() - 1);
/* 1257 */     int viCz = vcEnd - vcBegin;
/* 1258 */     pass = pass.substring(1);
/* 1259 */     pass = pass.substring(0, pass.length() - 1);
/* 1260 */     int viNum = 0;
/* 1261 */     for (int i = pass.length() - 1; i > 0; i -= 2)
/*      */     {
/*      */       char vcSecond;
/*      */       char vcFirst;
/*      */       char vcSecond;
/* 1265 */       if (++viNum % 2 == 1)
/*      */       {
/* 1267 */         char vcFirst = pass.charAt(i - 1);
/* 1268 */         vcSecond = pass.charAt(i);
/*      */       }
/*      */       else
/*      */       {
/* 1272 */         vcFirst = pass.charAt(i);
/* 1273 */         vcSecond = pass.charAt(i - 1);
/*      */       }
/* 1275 */       int viTemp = (vcFirst - vcBegin) * 26 + vcSecond - 'a' - viCz;
/* 1276 */       char[] chs = new char[1];
/* 1277 */       chs[0] = (char)viTemp;
/* 1278 */       String vsTemp = new String(chs);
/* 1279 */       vsPass = vsPass + vsTemp;
/*      */     }
/*      */ 
/* 1282 */     return vsPass;
/*      */   }
/*      */ 
/*      */   private static String makeDarkPass(String psPass)
/*      */   {
/* 1292 */     psPass = psPass.trim();
/* 1293 */     int viLength = psPass.length();
/* 1294 */     int viAscSum = 0;
/*      */ 
/* 1297 */     for (int i = 0; i < viLength; ++i)
/*      */     {
/* 1299 */       char vcChar = psPass.charAt(i);
/* 1300 */       int viTemp = vcChar;
/* 1301 */       if ((viTemp <= 122) && (((viTemp <= 90) || (viTemp >= 97))) && (viTemp >= 48) && (viTemp > 57));
/* 1305 */       viAscSum += viTemp;
/*      */     }
/*      */ 
/* 1308 */     int viSumMod = viAscSum % 26;
/* 1309 */     int viMaxMod = viSumMod;
/* 1310 */     char[] vsModStr = new char[viLength];
/* 1311 */     char[] vsDevStr = new char[viLength];
/* 1312 */     for (i = 0; i < viLength; ++i)
/*      */     {
/* 1314 */       char vcChar = psPass.charAt(i);
/* 1315 */       int viTemp = vcChar + viSumMod;
/* 1316 */       int viDev = viTemp / 26;
/* 1317 */       int viMod = viTemp - (viDev * 26);
/* 1318 */       if (viDev > viMaxMod)
/*      */       {
/* 1320 */         viMaxMod = viDev;
/*      */       }
/* 1322 */       vsModStr[i] = (char)(viMod + 97);
/* 1323 */       vsDevStr[i] = (char)viDev;
/*      */     }
/*      */ 
/* 1327 */     for (double vdTemp = Math.random() * 10.0D; vdTemp < 1.0D; vdTemp *= 10.0D);
/* 1331 */     int viTemp = (26 - viMaxMod) / (int)vdTemp;
/* 1332 */     char vcBegin = (char)(viTemp + 96);
/* 1333 */     char vcEnd = (char)(viTemp + viSumMod + 96);
/* 1334 */     for (i = 0; i < viLength; ++i)
/*      */     {
/* 1336 */       char vcChar = vsDevStr[i];
/* 1337 */       viTemp = vcBegin + vcChar;
/* 1338 */       vsDevStr[i] = (char)viTemp;
/*      */     }
/*      */ 
/* 1341 */     i = 0;
/* 1342 */     char[] vsTemp = new char[viLength * 2];
/* 1343 */     for (i = 0; i < viLength; ++i)
/*      */     {
/* 1345 */       if (i % 2 == 0)
/*      */       {
/* 1347 */         vsTemp[(2 * (viLength - i - 1))] = vsDevStr[i];
/* 1348 */         vsTemp[(2 * (viLength - i - 1) + 1)] = vsModStr[i];
/*      */       }
/*      */       else
/*      */       {
/* 1352 */         vsTemp[(2 * (viLength - i - 1))] = vsModStr[i];
/* 1353 */         vsTemp[(2 * (viLength - i - 1) + 1)] = vsDevStr[i];
/*      */       }
/*      */     }
/*      */ 
/* 1357 */     psPass = vcBegin + String.valueOf(vsTemp) + vcEnd;
/* 1358 */     return psPass; }
/*      */ 
/*      */   public static String getRandom(int len) {
/* 1361 */     int random = 0;
/* 1362 */     int length = (len >= 7) ? 7 : len;
/* 1363 */     for (int i = 0; i < 100; ++i) {
/* 1364 */       random = (int)(random + Math.random() * 100000.0D);
/*      */     }
/* 1366 */     return String.valueOf(random).substring(0, length); }
/*      */ 
/*      */   public static void main(String[] args) {
/* 1369 */     String oldPass = "htcash";
/*      */     try {
/* 1371 */       System.out.println(makeDarkPass(oldPass));
/* 1372 */       System.out.println(getClearPass("axddswdclffegweckn"));
/*      */     }
/*      */     catch (Exception ex) {
/* 1375 */       ToftLogger.error(ex.getMessage());
/*      */     }
/*      */   }
/*      */ }


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值