ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>2020中文字幕在线播放,久久不射网站,欧美自拍一区http://www.aygfsteel.com/parable-myth/category/16208.htmlJAVA、LINUX我的çˆ?我的世界zh-cnWed, 28 Feb 2007 07:54:20 GMTWed, 28 Feb 2007 07:54:20 GMT60md5½Ž—法http://www.aygfsteel.com/parable-myth/articles/74631.html我心飞翔我心飞翔Wed, 11 Oct 2006 09:25:00 GMThttp://www.aygfsteel.com/parable-myth/articles/74631.htmlhttp://www.aygfsteel.com/parable-myth/comments/74631.htmlhttp://www.aygfsteel.com/parable-myth/articles/74631.html#Feedback0http://www.aygfsteel.com/parable-myth/comments/commentRss/74631.htmlhttp://www.aygfsteel.com/parable-myth/services/trackbacks/74631.html package com.chinajavaworld.util;
 
import java.lang.reflect.*;
import java.io.*;
/*************************************************
md5 ¾cÕd®žçŽîCº†RSA Data Security, Inc.在提交给IETF
çš„RFC1321中的MD5 message-digest ½Ž—法ã€?br />*************************************************/

 
publicclass MD5 {
/* 下面˜q™äº›S11-S44实际上是一ä¸?*4的矩阵,在原始的C实现中是ç”?define 实现的,
˜q™é‡ŒæŠŠå®ƒä»¬å®žçŽ°æˆä¸ºstatic final是表½CÞZº†åªè¯»åQŒåˆ‡èƒ½åœ¨åŒä¸€ä¸ªè¿›½E‹ç©ºé—´å†…的多ä¸?br /> Instanceé—´å…±äº?/

staticfinalint S11 = 7;
staticfinalint S12 = 12;
staticfinalint S13 = 17;
staticfinalint S14 = 22;
 
staticfinalint S21 = 5;
staticfinalint S22 = 9;
staticfinalint S23 = 14;
staticfinalint S24 = 20;
 
staticfinalint S31 = 4;
staticfinalint S32 = 11;
staticfinalint S33 = 16;
staticfinalint S34 = 23;
 
staticfinalint S41 = 6;
staticfinalint S42 = 10;
staticfinalint S43 = 15;
staticfinalint S44 = 21;
 
staticfinalbyte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 下面的三个成员是MD5计算˜q‡ç¨‹ä¸­ç”¨åˆ°çš„3个核心数据,在原始的C实现ä¸?br /> 被定义到MD5_CTX¾l“æž„ä¸?br />
*/

privatelong[] state = newlong[4]; // state (ABCD)
privatelong[] count = newlong[2]; // number of bits, modulo 2^64 (lsb first)
privatebyte[] buffer = newbyte[64]; // input buffer
 
/* digestHexStr是MD5的唯一一个公共成员,是最æ–îC¸€‹Æ¡è®¡½Ž—结果的
  16˜q›åˆ¶ASCII表示.
*/

public String digestHexStr;
 
/* digest,是最æ–îC¸€‹Æ¡è®¡½Ž—结果的2˜q›åˆ¶å†…部表示åQŒè¡¨½C?28bitçš„MD5å€?
*/

privatebyte[] digest = newbyte[16];
 
/*
getMD5ofStr是类MD5最主要的公共方法,入口参数是你惌™¦˜q›è¡ŒMD5变换的字½W¦ä¸²
˜q”回的是变换完的¾l“æžœåQŒè¿™ä¸ªç»“果是从公共成员digestHexStr取得的.
*/

public String getMD5ofStr(String inbuf) {
md5Init();
try{
md5Update(inbuf.getBytes("GBK"),
inbuf.getBytes("GBK").length);
}
catch (UnsupportedEncodingException ex) {
}
md5Final();
digestHexStr = "";
for (int i = 0; i < 16; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr;
 
}
// ˜q™æ˜¯MD5˜q™ä¸ª¾cÈš„æ ‡å‡†æž„造函敎ͼŒJavaBean要求有一个publicçš„åÆˆä¸”æ²¡æœ‰å‚æ•°çš„æž„é€ å‡½æ•?/font>
public MD5() {
md5Init();
 
return;
}
 
 
 
/* md5Init是一个初始化函数åQŒåˆå§‹åŒ–核心变量åQŒè£…入标准的òqÀL•° */
privatevoid md5Init() {
count[0] = 0L;
count[1] = 0L;
///* Load magic initialization constants.
 
state[0] = 0x67452301L;
state[1] = 0xefcdab89L;
state[2] = 0x98badcfeL;
state[3] = 0x10325476L;
 
return;
}
/* F, G, H ,I æ˜?个基本的MD5函数åQŒåœ¨åŽŸå§‹çš„MD5çš„C实现中,ç”׃ºŽå®ƒä»¬æ˜?br /> ½Ž€å•的位运½Ž—,可能å‡ÞZºŽæ•ˆçŽ‡çš„è€ƒè™‘æŠŠå®ƒä»¬å®žçŽ°æˆäº†å®åQŒåœ¨java中,我们把它ä»?br />   实现成了privateæ–ÒŽ³•åQŒåå­—保持了原来C中的ã€?*/
 
privatelong F(long x, long y, long z) {
return (x & y) | ((~x) & z);
 
}
privatelong G(long x, long y, long z) {
return (x & z) | (y & (~z));
 
}
privatelong H(long x, long y, long z) {
return x ^ y ^ z;
}
 
privatelong I(long x, long y, long z) {
return y ^ (x | (~z));
}
 
/*
FF,GG,HHå’ŒIIž®†è°ƒç”¨F,G,H,I˜q›è¡Œ˜q‘一步变æ?br /> FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/

 
privatelong FF(long a, long b, long c, long d, long x, long s,
long ac) {
a += F (b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
 
privatelong GG(long a, long b, long c, long d, long x, long s,
long ac) {
a += G (b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
privatelong HH(long a, long b, long c, long d, long x, long s,
long ac) {
a += H (b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
privatelong II(long a, long b, long c, long d, long x, long s,
long ac) {
a += I (b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
/*
md5Update是MD5的主计算˜q‡ç¨‹åQŒinbuf是要变换的字节串åQŒinputlen是长度,˜q™ä¸ª
函数由getMD5ofStr调用åQŒè°ƒç”¨ä¹‹å‰éœ€è¦è°ƒç”¨md5initåQŒå› æ­¤æŠŠå®ƒè®¾è®¡æˆprivateçš?br /> */

privatevoid md5Update(byte[] inbuf, int inputLen) {
 
int i, index, partLen;
byte[] block = newbyte[64];
index = (int)(count[0] >>> 3) & 0x3F;
// /* Update number of bits */
if ((count[0] += (inputLen << 3)) < (inputLen << 3))
count[1]++;
count[1] += (inputLen >>> 29);
 
partLen = 64 - index;
 
// Transform as many times as possible.
if (inputLen >= partLen) {
md5Memcpy(buffer, inbuf, index, 0, partLen);
md5Transform(buffer);
 
for (i = partLen; i + 63 < inputLen; i += 64) {
 
md5Memcpy(block, inbuf, 0, i, 64);
md5Transform (block);
}
index = 0;
 
}else
 
i = 0;
 
///* Buffer remaining input */
md5Memcpy(buffer, inbuf, index, i, inputLen - i);
 
}
 
/*
md5Final整理和填写输出结�br /> */

privatevoid md5Final () {
byte[] bits = newbyte[8];
int index, padLen;
 
///* Save number of bits */
Encode (bits, count, 8);
 
///* Pad out to 56 mod 64.
index = (int)(count[0] >>> 3) & 0x3f;
padLen = (index < 56) ? (56 - index) : (120 - index);
md5Update (PADDING, padLen);
 
///* Append length (before padding) */
md5Update(bits, 8);
 
///* Store state in digest */
Encode (digest, state, 16);
 
}
 
/* md5Memcpy是一个内部ä‹É用的byte数组的块拯‚´å‡½æ•°åQŒä»Žinputçš„inpos开始把len长度çš?br />      字节拯‚´åˆ°outputçš„outpos位置开å§?br /> */
 
privatevoid md5Memcpy (byte[] output, byte[] input,
int outpos, int inpos, int len)
{
int i;
 
for (i = 0; i < len; i++)
output[outpos + i] = input[inpos + i];
}
 
/*
md5Transform是MD5核心变换½E‹åºåQŒæœ‰md5Update调用åQŒblock是分块的原始字节
*/

privatevoid md5Transform (byte block[]) {
long a = state[0], b = state[1], c = state[2], d = state[3];
long[] x = newlong[16];
 
Decode (x, block, 64);
 
/* Round 1 */
a = FF (a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
d = FF (d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
c = FF (c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
b = FF (b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
a = FF (a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
d = FF (d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
c = FF (c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
b = FF (b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
a = FF (a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
d = FF (d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
c = FF (c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
b = FF (b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
a = FF (a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
d = FF (d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
c = FF (c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
b = FF (b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */
 
/* Round 2 */
a = GG (a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
d = GG (d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
c = GG (c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
b = GG (b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
a = GG (a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
d = GG (d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
c = GG (c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
b = GG (b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
a = GG (a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
d = GG (d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
c = GG (c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
b = GG (b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
a = GG (a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
d = GG (d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
c = GG (c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
b = GG (b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */
 
/* Round 3 */
a = HH (a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
d = HH (d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
c = HH (c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
b = HH (b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
a = HH (a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
d = HH (d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
c = HH (c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
b = HH (b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
a = HH (a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
d = HH (d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
c = HH (c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
b = HH (b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
a = HH (a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
d = HH (d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
c = HH (c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
b = HH (b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */
 
/* Round 4 */
a = II (a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
d = II (d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
c = II (c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
b = II (b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
a = II (a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
d = II (d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
c = II (c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
b = II (b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
a = II (a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
d = II (d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
c = II (c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
b = II (b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
a = II (a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
d = II (d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
c = II (c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
b = II (b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */
 
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
 
}
 
/*Encode把long数组按顺序拆成byte数组åQŒå› ä¸ºjavaçš„long¾cÕdž‹æ˜?4bit的,
只拆ä½?2bitåQŒä»¥é€‚应原始C实现的用é€?br /> */

privatevoid Encode (byte[] output, long[] input, int len) {
int i, j;
 
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (byte)(input[i] & 0xffL);
output[j + 1] = (byte)((input[i] >>> 8) & 0xffL);
output[j + 2] = (byte)((input[i] >>> 16) & 0xffL);
output[j + 3] = (byte)((input[i] >>> 24) & 0xffL);
}
}
 
/*Decode把byte数组按顺序合成成long数组åQŒå› ä¸ºjavaçš„long¾cÕdž‹æ˜?4bit的,
只合成低32bitåQŒé«˜32bit清零åQŒä»¥é€‚应原始C实现的用é€?br /> */

privatevoid Decode (long[] output, byte[] input, int len) {
int i, j;
 
 
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = b2iu(input[j]) |
(b2iu(input[j + 1]) << 8) |
(b2iu(input[j + 2]) << 16) |
(b2iu(input[j + 3]) << 24);
 
return;
}
 
/*
b2iu是我写的一个把byte按照不考虑正负åïLš„原则的"升位åQ‚ç¨‹åºï¼Œå› äØ“java没有unsigned˜qç®—
*/

publicstaticlong b2iu(byte b) {
return b < 0 ? b & 0x7F + 128 : b;
}
 
/*byteHEX()åQŒç”¨æ¥æŠŠä¸€ä¸ªbyte¾cÕdž‹çš„æ•°è½¬æ¢æˆåå…­è¿›åˆ¶çš„ASCII表示åQ?br /> ã€€å› äØ“java中的byteçš„toString无法实现˜q™ä¸€ç‚¹ï¼Œæˆ‘们又没有C语言中的
sprintf(outbuf,"%02X",ib)
*/

publicstatic String byteHEX(byte ib) {
char[] Digit = {'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F'};
char [] ob = newchar[2];
ob[0] = Digit[(ib >>> 4) & 0X0F];
ob[1] = Digit[ib & 0X0F];
String s = new String(ob);
return s;
}
 
publicstaticvoid main(String args[]) {
 
 
MD5 m = new MD5();
if (Array.getLength(args) == 0) {//如果没有参数åQŒæ‰§è¡Œæ ‡å‡†çš„Test Suite
 
System.out.println("MD5 Test suite:");
System.out.println("MD5(\"\"):"+m.getMD5ofStr(""));
System.out.println("MD5(\"a\"):"+m.getMD5ofStr("a"));
System.out.println("MD5(\"abc\"):"+m.getMD5ofStr("abc"));
System.out.println("MD5(\"message digest\"):"+m.getMD5ofStr("message digest"));
System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):"+
m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz"));
System.out.println("MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"+
m.getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
}
else
System.out.println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0]));
 
 
}
 
}

]]>
获取¾|‘卡信息http://www.aygfsteel.com/parable-myth/articles/74630.html我心飞翔我心飞翔Wed, 11 Oct 2006 09:23:00 GMThttp://www.aygfsteel.com/parable-myth/articles/74630.htmlhttp://www.aygfsteel.com/parable-myth/comments/74630.htmlhttp://www.aygfsteel.com/parable-myth/articles/74630.html#Feedback0http://www.aygfsteel.com/parable-myth/comments/commentRss/74630.htmlhttp://www.aygfsteel.com/parable-myth/services/trackbacks/74630.html import java.net.*;
//...
 
System.out.println("\n+---------------------[ Network Cards ]----------------------+\n");
try
{
for(Enumeration list = NetworkInterface.getNetworkInterfaces(); list.hasMoreElements();)
{
NetworkInterface iFace = (NetworkInterface)list.nextElement();
System.out.println("Card:" + iFace.getDisplayName());
InetAddress adr;
for(Enumeration addresses = iFace.getInetAddresses(); addresses.hasMoreElements(); System.out.println(" -> " + adr.getHostAddress()))
adr = (InetAddress)addresses.nextElement();
 
}
 
}
catch(SocketException se)
{
System.out.println("Failed discovering network cards!");
System.out.println("Error: " + se);
}

]]>
æ—‰™—´æ˜„¡¤ºæ“ä½œ¾c?/title><link>http://www.aygfsteel.com/parable-myth/articles/74627.html</link><dc:creator>我心飞翔</dc:creator><author>我心飞翔</author><pubDate>Wed, 11 Oct 2006 09:15:00 GMT</pubDate><guid>http://www.aygfsteel.com/parable-myth/articles/74627.html</guid><wfw:comment>http://www.aygfsteel.com/parable-myth/comments/74627.html</wfw:comment><comments>http://www.aygfsteel.com/parable-myth/articles/74627.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/parable-myth/comments/commentRss/74627.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/parable-myth/services/trackbacks/74627.html</trackback:ping><description><![CDATA[ <pre> <font color="navy"> <b>package</b> </font> com.chinajavaworld.util;<br /> <br /><font color="navy"><b>import</b></font> java.text.ParseException;<br /><font color="navy"><b>import</b></font> java.text.SimpleDateFormat;<br /><font color="navy"><b>import</b></font> java.util.Calendar;<br /><font color="navy"><b>import</b></font> java.util.Date;<br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>class</b></font> DateTimeUtil<br /><font color="navy">{</font><br /> <br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font><font color="navy"><b>int</b></font> MAJOR_VERSION = 1;<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font><font color="navy"><b>int</b></font> MINOR_VERSION = 0;<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font><font color="navy"><b>int</b></font> REVISION_VERSION = 1;<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> String showFormat = <font color="red">"yyyy-MM-dd HH:mm:ss"</font>;<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> String storeFormat = <font color="red">"yyyyMMddHHmmssSSS"</font>;<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat showFormater = <font color="navy"><b>new</b></font> SimpleDateFormat(showFormat);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat storeFormater = <font color="navy"><b>new</b></font> SimpleDateFormat(storeFormat);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat formatter1 = <font color="navy"><b>new</b></font> SimpleDateFormat (<font color="red">"yyyyòq´MM月ddæ—?HHæ—¶mm分ss¿U?</font>);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat formatter2 = <font color="navy"><b>new</b></font> SimpleDateFormat (<font color="red">"yyyyòq´MM月ddæ—?</font>);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat formatter3 = <font color="navy"><b>new</b></font> SimpleDateFormat (<font color="red">"yyyy-MM-dd HH:mm:ss"</font>);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat formatter4 = <font color="navy"><b>new</b></font> SimpleDateFormat (<font color="red">"yyyy-MM-dd"</font>);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat formatter5 = <font color="navy"><b>new</b></font> SimpleDateFormat (<font color="red">"yyyy/MM/dd"</font>);<br /><font color="navy"><b>private</b></font><font color="navy"><b>static</b></font><font color="navy"><b>final</b></font> SimpleDateFormat formatter6 = <font color="navy"><b>new</b></font> SimpleDateFormat (<font color="red">"MM-dd HH:mm"</font>);<br /> <br /><font color="navy"><b>public</b></font> DateTimeUtil()<br /><font color="navy">{</font><br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getNow()<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> storeFormater.format(<font color="navy"><b>new</b></font> Date());<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getRelativeDate(<font color="navy"><b>int</b></font> days)<br /><font color="navy">{</font><br /> Calendar c = Calendar.getInstance();<br /> c.set(5, c.get(5) + days);<br /> StringBuffer sb = <font color="navy"><b>new</b></font> StringBuffer(17);<br /> sb.append(c.get(1));<br /><font color="navy"><b>int</b></font> tmp[] = <font color="navy">{</font><br /> c.get(2) + 1, c.get(5), c.get(11), c.get(12), c.get(13), c.get(14)<br /><font color="navy">}</font>;<br /><font color="navy"><b>for</b></font>(<font color="navy"><b>int</b></font> i = 0; i < tmp.length - 1; i++)<br /> sb.append(tmp[i] >= 10 ? <font color="red">""</font> : <font color="red">"0"</font>).append(tmp[i]);<br /> <br /><font color="navy"><b>if</b></font>(tmp[tmp.length - 1] < 10)<br /> sb.append(<font color="red">"0"</font>);<br /><font color="navy"><b>if</b></font>(tmp[tmp.length - 1] < 100)<br /> sb.append(<font color="red">"0"</font>);<br /> sb.append(tmp[tmp.length - 1]);<br /><font color="navy"><b>return</b></font> sb.toString();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getNow(String string)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> (<font color="navy"><b>new</b></font> SimpleDateFormat(string)).format(<font color="navy"><b>new</b></font> Date());<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getDisplayTime(<font color="navy"><b>long</b></font> time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> showFormater.format(<font color="navy"><b>new</b></font> Date(time));<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getDisplayTime(<font color="navy"><b>long</b></font> time, String string)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> (<font color="navy"><b>new</b></font> SimpleDateFormat(string)).format(<font color="navy"><b>new</b></font> Date(time));<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getShowFormat(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>try</b></font><br /><font color="navy">{</font><br /><font color="navy"><b>if</b></font>(time == <font color="navy"><b>null</b></font> || time.equals(<font color="red">""</font>))<br /> time = showFormater.format(<font color="navy"><b>new</b></font> Date());<br /><font color="navy"><b>else</b></font><br /> time = showFormater.format(storeFormater.parse(time));<br /><font color="navy">}</font><br /><font color="navy"><b>catch</b></font>(ParseException e)<br /><font color="navy">{</font><br /> e.printStackTrace();<br /><font color="navy">}</font><br /><font color="navy"><b>return</b></font> time;<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>long</b></font> compare(String t1, String t2)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Long.valueOf(t1).longValue() - Long.valueOf(t2).longValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getYear(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(0, 4)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getMonth(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(4, 6)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getDate(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(6, 8)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getHour(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(8, 10)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getMinute(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(10, 12)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getSecond(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(12, 14)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getMilliSencond(String time)<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> Integer.valueOf(time.substring(14, 17)).intValue();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>long</b></font> getTimeStamp(String time)<br /><font color="navy"><b>throws</b></font> ParseException<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> storeFormater.parse(time).getTime();<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String formatDate1(Date myDate) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> formatter1.format(myDate);<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String formatDate2(Date myDate) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> formatter2.format(myDate);<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String formatDate3(Date myDate) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> formatter3.format(myDate);<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String formatDate4(Date myDate) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> formatter4.format(myDate);<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String formatDate5(Date myDate) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> formatter5.format(myDate);<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String formatDate6(Date myDate) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> formatter6.format(myDate);<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>long</b></font> getLongTime(String time)<font color="navy">{</font><br /><font color="navy"><b>try</b></font><font color="navy">{</font><br /><font color="navy"><b>return</b></font> showFormater.parse(time).getTime();<br /><font color="navy">}</font><br /><font color="navy"><b>catch</b></font> (ParseException ex) <font color="navy">{</font><br /><font color="navy"><b>return</b></font> 0L;<br /><font color="navy">}</font><br /><font color="navy">}</font><br /> <br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font> String getVersion()<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font><font color="red">"1.0.1"</font>;<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getMajor()<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> 1;<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getMinor()<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> 0;<br /><font color="navy">}</font><br /> <br /><font color="navy"><b>public</b></font><font color="navy"><b>static</b></font><font color="navy"><b>int</b></font> getRevision()<br /><font color="navy">{</font><br /><font color="navy"><b>return</b></font> 1;<br /><font color="navy">}</font><br /> <br /><font color="navy">}</font></pre> <img src ="http://www.aygfsteel.com/parable-myth/aggbug/74627.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/parable-myth/" target="_blank">我心飞翔</a> 2006-10-11 17:15 <a href="http://www.aygfsteel.com/parable-myth/articles/74627.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>request参数接收解析http://www.aygfsteel.com/parable-myth/articles/74626.html我心飞翔我心飞翔Wed, 11 Oct 2006 09:13:00 GMThttp://www.aygfsteel.com/parable-myth/articles/74626.htmlhttp://www.aygfsteel.com/parable-myth/comments/74626.htmlhttp://www.aygfsteel.com/parable-myth/articles/74626.html#Feedback0http://www.aygfsteel.com/parable-myth/comments/commentRss/74626.htmlhttp://www.aygfsteel.com/parable-myth/services/trackbacks/74626.html package com.chinajavaworld.util;
 
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
 
publicclass ParamUtils
{
 
public ParamUtils()
{
}
 
publicstatic String getParameter(HttpServletRequest request, String name)
{
return getParameter(request, name, false);
}
 
publicstatic String getParameter(HttpServletRequest request, String name, String defaultValue)
{
return getParameter(request, name, defaultValue, false);
}
 
publicstatic String getParameter(HttpServletRequest request, String name, boolean emptyStringsOK)
{
return getParameter(request, name, null, emptyStringsOK);
}
 
publicstatic String getParameter(HttpServletRequest request, String name, String defaultValue, boolean emptyStringsOK)
{
String temp = request.getParameter(name);
if(temp != null)
{
if(temp.equals("") && !emptyStringsOK)
return defaultValue;
else
return temp;
}else
{
return defaultValue;
}
}
 
publicstatic String[] getParameters(HttpServletRequest request, String name)
{
if(name == null)
returnnew String[0];
String paramValues[] = request.getParameterValues(name);
if(paramValues == null || paramValues.length == 0)
returnnew String[0];
List values = new ArrayList(paramValues.length);
for(int i = 0; i < paramValues.length; i++)
if(paramValues[i] != null && !"".equals(paramValues[i]))
values.add(paramValues[i]);
 
return (String[])values.toArray(new String[0]);
}
 
publicstaticboolean getBooleanParameter(HttpServletRequest request, String name)
{
return getBooleanParameter(request, name, false);
}
 
publicstaticboolean getBooleanParameter(HttpServletRequest request, String name, boolean defaultVal)
{
String temp = request.getParameter(name);
if("true".equals(temp) || "on".equals(temp))
returntrue;
if("false".equals(temp) || "off".equals(temp))
returnfalse;
else
return defaultVal;
}
 
publicstaticint getIntParameter(HttpServletRequest request, String name, int defaultNum)
{
String temp = request.getParameter(name);
if(temp != null && !temp.equals(""))
{
int num = defaultNum;
try
{
num = Integer.parseInt(temp.trim());
}
catch(Exception ignored) {}
return num;
}else
{
return defaultNum;
}
}
 
publicstaticint[] getIntParameters(HttpServletRequest request, String name, int defaultNum)
{
String paramValues[] = request.getParameterValues(name);
if(paramValues == null || paramValues.length == 0)
returnnewint[0];
int values[] = newint[paramValues.length];
for(int i = 0; i < paramValues.length; i++)
try
{
values[i] = Integer.parseInt(paramValues[i].trim());
}
catch(Exception e)
{
values[i] = defaultNum;
}
 
return values;
}
 
publicstaticdouble getDoubleParameter(HttpServletRequest request, String name, double defaultNum)
{
String temp = request.getParameter(name);
if(temp != null && !temp.equals(""))
{
double num = defaultNum;
try
{
num = Double.parseDouble(temp.trim());
}
catch(Exception ignored) {}
return num;
}else
{
return defaultNum;
}
}
 
publicstaticlong getLongParameter(HttpServletRequest request, String name, long defaultNum)
{
String temp = request.getParameter(name);
if(temp != null && !temp.equals(""))
{
long num = defaultNum;
try
{
num = Long.parseLong(temp.trim());
}
catch(Exception ignored) {}
return num;
}else
{
return defaultNum;
}
}
 
publicstaticlong[] getLongParameters(HttpServletRequest request, String name, long defaultNum)
{
String paramValues[] = request.getParameterValues(name);
if(paramValues == null || paramValues.length == 0)
returnnewlong[0];
long values[] = newlong[paramValues.length];
for(int i = 0; i < paramValues.length; i++)
try
{
values[i] = Long.parseLong(paramValues[i].trim());
}
catch(Exception e)
{
values[i] = defaultNum;
}
 
return values;
}
 
publicstatic String getAttribute(HttpServletRequest request, String name)
{
return getAttribute(request, name, false);
}
 
publicstatic String getAttribute(HttpServletRequest request, String name, boolean emptyStringsOK)
{
String temp = (String)request.getAttribute(name);
if(temp != null)
{
if(temp.equals("") && !emptyStringsOK)
returnnull;
else
return temp;
}else
{
returnnull;
}
}
 
publicstaticboolean getBooleanAttribute(HttpServletRequest request, String name)
{
String temp = (String)request.getAttribute(name);
return temp != null && temp.equals("true");
}
 
publicstaticint getIntAttribute(HttpServletRequest request, String name, int defaultNum)
{
String temp = (String)request.getAttribute(name);
if(temp != null && !temp.equals(""))
{
int num = defaultNum;
try
{
num = Integer.parseInt(temp.trim());
}
catch(Exception ignored) {}
return num;
}else
{
return defaultNum;
}
}
 
publicstaticlong getLongAttribute(HttpServletRequest request, String name, long defaultNum)
{
String temp = (String)request.getAttribute(name);
if(temp != null && !temp.equals(""))
{
long num = defaultNum;
try
{
num = Long.parseLong(temp.trim());
}
catch(Exception ignored) {}
return num;
}else
{
return defaultNum;
}
}
}

]]>
字符串处理等常用æ–ÒŽ³• http://www.aygfsteel.com/parable-myth/articles/74624.html我心飞翔我心飞翔Wed, 11 Oct 2006 09:11:00 GMThttp://www.aygfsteel.com/parable-myth/articles/74624.htmlhttp://www.aygfsteel.com/parable-myth/comments/74624.htmlhttp://www.aygfsteel.com/parable-myth/articles/74624.html#Feedback0http://www.aygfsteel.com/parable-myth/comments/commentRss/74624.htmlhttp://www.aygfsteel.com/parable-myth/services/trackbacks/74624.htmlpackage com.chinajavaworld.util;
 
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.BreakIterator;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.File;
 
public class StringUtils
{
  private final static String BR_TAG = "<BR>";
 
    private StringUtils()
    {
    }
 
    /**
     * This method takes a string which may contain newline characters
     * '\n' which it converts to html newline tags.
     *
     * @param input The text to be converted.
     * @return The input string with the newline character '\n' replaced
     * with <br>.
     */
    public static final String convertNewlines(String input) {
      return replace(replace(input, "\r\n", BR_TAG), "\n", BR_TAG);
    }
 
    public static final String backConvertNewlines(String input) {
      return replaceIgnoreCase(input, BR_TAG, "\n");
    }
 
 
    public static final String replace(String string, String oldString, String newString)
    {
        if(string == null)
            return null;
        if(newString == null)
            return string;
        int i = 0;
        if((i = string.indexOf(oldString, i)) >= 0)
        {
            char string2[] = string.toCharArray();
            char newString2[] = newString.toCharArray();
            int oLength = oldString.length();
            StringBuffer buf = new StringBuffer(string2.length);
            buf.append(string2, 0, i).append(newString2);
            i += oLength;
            int j;
            for(j = i; (i = string.indexOf(oldString, i)) > 0; j = i)
            {
                buf.append(string2, j, i - j).append(newString2);
                i += oLength;
            }
 
            buf.append(string2, j, string2.length - j);
            return buf.toString();
        } else
        {
            return string;
        }
    }
 
    public static final String replaceIgnoreCase(String line, String oldString, String newString)
    {
        if(line == null)
            return null;
        String lcLine = line.toLowerCase();
        String lcOldString = oldString.toLowerCase();
        int i = 0;
        if((i = lcLine.indexOf(lcOldString, i)) >= 0)
        {
            char line2[] = line.toCharArray();
            char newString2[] = newString.toCharArray();
            int oLength = oldString.length();
            StringBuffer buf = new StringBuffer(line2.length);
            buf.append(line2, 0, i).append(newString2);
            i += oLength;
            int j;
            for(j = i; (i = lcLine.indexOf(lcOldString, i)) > 0; j = i)
            {
                buf.append(line2, j, i - j).append(newString2);
                i += oLength;
            }
 
            buf.append(line2, j, line2.length - j);
            return buf.toString();
        } else
        {
            return line;
        }
    }
 
    public static final String replaceIgnoreCase(String line, String oldString, String newString, int count[])
    {
        if(line == null)
            return null;
        String lcLine = line.toLowerCase();
        String lcOldString = oldString.toLowerCase();
        int i = 0;
        if((i = lcLine.indexOf(lcOldString, i)) >= 0)
        {
            int counter = 1;
            char line2[] = line.toCharArray();
            char newString2[] = newString.toCharArray();
            int oLength = oldString.length();
            StringBuffer buf = new StringBuffer(line2.length);
            buf.append(line2, 0, i).append(newString2);
            i += oLength;
            int j;
            for(j = i; (i = lcLine.indexOf(lcOldString, i)) > 0; j = i)
            {
                counter++;
                buf.append(line2, j, i - j).append(newString2);
                i += oLength;
            }
 
            buf.append(line2, j, line2.length - j);
            count[0] = counter;
            return buf.toString();
        } else
        {
            return line;
        }
    }
 
    public static final String replace(String line, String oldString, String newString, int count[])
    {
        if(line == null)
            return null;
        int i = 0;
        if((i = line.indexOf(oldString, i)) >= 0)
        {
            int counter = 1;
            char line2[] = line.toCharArray();
            char newString2[] = newString.toCharArray();
            int oLength = oldString.length();
            StringBuffer buf = new StringBuffer(line2.length);
            buf.append(line2, 0, i).append(newString2);
            i += oLength;
            int j;
            for(j = i; (i = line.indexOf(oldString, i)) > 0; j = i)
            {
                counter++;
                buf.append(line2, j, i - j).append(newString2);
                i += oLength;
            }
 
            buf.append(line2, j, line2.length - j);
            count[0] = counter;
            return buf.toString();
        } else
        {
            return line;
        }
    }
 
    public static final boolean hasBadwordsIgnoreCase(String line, String oldString)
    {
        if(line == null)
            return false;
        String lcLine = line.toLowerCase();
        String lcOldString = oldString.toLowerCase();
        int i = 0;
        if((i = lcLine.indexOf(lcOldString, i)) >= 0)
        {
            return true;
        } else
        {
            return false;
        }
    }
 
    public static final String stripTags(String in)
    {
        if(in == null)
            return null;
        else
            return stripTags(in, false);
    }
 
    public static final String stripTags(String in, boolean stripBRTag)
    {
        if(in == null)
            return null;
        int i = 0;
        int last = 0;
        char input[] = in.toCharArray();
        int len = input.length;
        StringBuffer out = new StringBuffer((int)((double)len * 1.3D));
        for(; i < len; i++)
        {
            char ch = input[i];
            if(ch > '>')
                continue;
            if(ch == '<')
            {
                if(!stripBRTag && i + 3 < len && input[i + 1] == 'b' && input[i + 2] == 'r' && input[i + 3] == '>')
                {
                    i += 3;
                    continue;
                }
                if(i > last)
                {
                    if(last > 0)
                        out.append(" ");
                    out.append(input, last, i - last);
                }
                last = i + 1;
                continue;
            }
            if(ch == '>')
                last = i + 1;
        }
 
        if(last == 0)
            return in;
        if(i > last)
            out.append(input, last, i - last);
        return out.toString();
    }
 
    public static final String escapeHTMLTags(String in)
    {
        if(in == null)
            return null;
        int i = 0;
        int last = 0;
        char input[] = in.toCharArray();
        int len = input.length;
        StringBuffer out = new StringBuffer((int)((double)len * 1.3D));
        for(; i < len; i++)
        {
            char ch = input[i];
            if(ch > '>')
                continue;
            if(ch == '<')
            {
                if(i > last)
                    out.append(input, last, i - last);
                last = i + 1;
                out.append(LT_ENCODE);
                continue;
            }
            if(ch == '>')
            {
                if(i > last)
                    out.append(input, last, i - last);
                last = i + 1;
                out.append(GT_ENCODE);
                continue;
            }
            if(ch != '"')
                continue;
            if(i > last)
                out.append(input, last, i - last);
            last = i + 1;
            out.append(QUOTE_ENCODE);
        }
 
        if(last == 0)
            return in;
        if(i > last)
            out.append(input, last, i - last);
        return out.toString();
    }
 
    public static final synchronized String hash(String data)
    {
        if(digest == null)
            try
            {
                digest = MessageDigest.getInstance("MD5");
            }
            catch(NoSuchAlgorithmException nsae)
            {
                //Log.error(e);
            }
        try
        {
            digest.update(data.getBytes("utf-8"));
        }
        catch(UnsupportedEncodingException e)
        {
            //Log.error(e);
        }
        return encodeHex(digest.digest());
    }
 
    public static final String encodeHex(byte bytes[])
    {
        StringBuffer buf = new StringBuffer(bytes.length * 2);
        for(int i = 0; i < bytes.length; i++)
        {
            if((bytes[i] & 0xff) < 16)
                buf.append("0");
            buf.append(Long.toString(bytes[i] & 0xff, 16));
        }
 
        return buf.toString();
    }
 
    public static final byte[] decodeHex(String hex)
    {
        char chars[] = hex.toCharArray();
        byte bytes[] = new byte[chars.length / 2];
        int byteCount = 0;
        for(int i = 0; i < chars.length; i += 2)
        {
            int newByte = 0;
            newByte |= hexCharToByte(chars[i]);
            newByte <<= 4;
            newByte |= hexCharToByte(chars[i + 1]);
            bytes[byteCount] = (byte)newByte;
            byteCount++;
        }
 
        return bytes;
    }
 
    private static final byte hexCharToByte(char ch)
    {
        switch(ch)
        {
        case 48: // '0'
            return 0;
 
        case 49: // '1'
            return 1;
 
        case 50: // '2'
            return 2;
 
        case 51: // '3'
            return 3;
 
        case 52: // '4'
            return 4;
 
        case 53: // '5'
            return 5;
 
        case 54: // '6'
            return 6;
 
        case 55: // '7'
            return 7;
 
        case 56: // '8'
            return 8;
 
        case 57: // '9'
            return 9;
 
        case 97: // 'a'
            return 10;
 
        case 98: // 'b'
            return 11;
 
        case 99: // 'c'
            return 12;
 
        case 100: // 'd'
            return 13;
 
        case 101: // 'e'
            return 14;
 
        case 102: // 'f'
            return 15;
 
        case 58: // ':'
        case 59: // ';'
        case 60: // '<'
        case 61: // '='
        case 62: // '>'
        case 63: // '?'
        case 64: // '@'
        case 65: // 'A'
        case 66: // 'B'
        case 67: // 'C'
        case 68: // 'D'
        case 69: // 'E'
        case 70: // 'F'
        case 71: // 'G'
        case 72: // 'H'
        case 73: // 'I'
        case 74: // 'J'
        case 75: // 'K'
        case 76: // 'L'
        case 77: // 'M'
        case 78: // 'N'
        case 79: // 'O'
        case 80: // 'P'
        case 81: // 'Q'
        case 82: // 'R'
        case 83: // 'S'
        case 84: // 'T'
        case 85: // 'U'
        case 86: // 'V'
        case 87: // 'W'
        case 88: // 'X'
        case 89: // 'Y'
        case 90: // 'Z'
        case 91: // '['
        case 92: // '\\'
        case 93: // ']'
        case 94: // '^'
        case 95: // '_'
        case 96: // '`'
        default:
            return 0;
        }
    }
 
    public static String encodeBase64(String data)
    {
        byte bytes[] = null;
        try
        {
            bytes = data.getBytes("UTF-8");
        }
        catch(UnsupportedEncodingException uee)
        {
            //Log.error(uee);
        }
        return encodeBase64(bytes);
    }
 
    public static String decodeBase64(String data)
    {
        byte[] bytes = null;
        try {
          bytes = data.getBytes("UTF-8");
          return new String(decodeBase64(bytes), "UTF-8");
        }
        catch (UnsupportedEncodingException ex) {
        }
        return "";
    }
 
    public static String encodeBase64(byte data[])
    {
        boolean lineSep = false;
        int sLen = data == null ? 0 : data.length;
        if(sLen == 0)
            return new String("");
        int eLen = (sLen / 3) * 3;
        int cCnt = (sLen - 1) / 3 + 1 << 2;
        int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0);
        char dArr[] = new char[dLen];
        int s = 0;
        int d = 0;
        int cc = 0;
        do
        {
            if(s >= eLen)
                break;
            int i = (data[s++] & 0xff) << 16 | (data[s++] & 0xff) << 8 | data[s++] & 0xff;
            dArr[d++] = CA[i >>> 18 & 0x3f];
            dArr[d++] = CA[i >>> 12 & 0x3f];
            dArr[d++] = CA[i >>> 6 & 0x3f];
            dArr[d++] = CA[i & 0x3f];
            if(lineSep && ++cc == 19 && d < dLen - 2)
            {
                dArr[d++] = '\r';
                dArr[d++] = '\n';
                cc = 0;
            }
        } while(true);
        int left = sLen - eLen;
        if(left > 0)
        {
            int i = (data[eLen] & 0xff) << 10 | (left != 2 ? 0 : (data[sLen - 1] & 0xff) << 2);
            dArr[dLen - 4] = CA[i >> 12];
            dArr[dLen - 3] = CA[i >>> 6 & 0x3f];
            dArr[dLen - 2] = left != 2 ? '=' : CA[i & 0x3f];
            dArr[dLen - 1] = '=';
        }
        return new String(dArr);
    }
 
    public static final byte[] decodeBase64(byte bytes[])
    {
        int sLen = bytes.length;
        int sepCnt = 0;
        for(int i = 0; i < sLen; i++)
            if(IA[bytes[i] & 0xff] < 0)
                sepCnt++;
 
        if((sLen - sepCnt) % 4 != 0)
            return null;
        int pad = 0;
        int i = sLen;
        do
        {
            if(i <= 1 || IA[bytes[--i] & 0xff] > 0)
                break;
            if(bytes[i] == 61)
                pad++;
        } while(true);
        int len = ((sLen - sepCnt) * 6 >> 3) - pad;
        byte dArr[] = new byte[len];
        int s = 0;
        int d = 0;
        do
        {
            if(d >= len)
                break;
            i = 0;
            for(int j = 0; j < 4; j++)
            {
                int c = IA[bytes[s++] & 0xff];
                if(c >= 0)
                    i |= c << 18 - j * 6;
                else
                    j--;
            }
 
            dArr[d++] = (byte)(i >> 16);
            if(d < len)
            {
                dArr[d++] = (byte)(i >> 8);
                if(d < len)
                    dArr[d++] = (byte)i;
            }
        } while(true);
        return dArr;
    }
 
    public static String URLEncode(String original, String charset)
        throws UnsupportedEncodingException
    {
        if(original == null)
            return null;
        byte octets[];
        try
        {
            octets = original.getBytes(charset);
        }
        catch(UnsupportedEncodingException error)
        {
            throw new UnsupportedEncodingException();
        }
        StringBuffer buf = new StringBuffer(octets.length);
        for(int i = 0; i < octets.length; i++)
        {
            char c = (char)octets[i];
            if(allowed_query.get(c))
            {
                buf.append(c);
            } else
            {
                buf.append('%');
                byte b = octets[i];
                char hexadecimal = Character.forDigit(b >> 4 & 0xf, 16);
                buf.append(Character.toUpperCase(hexadecimal));
                hexadecimal = Character.forDigit(b & 0xf, 16);
                buf.append(Character.toUpperCase(hexadecimal));
            }
        }
 
        return buf.toString();
    }
 
    public static final String[] toLowerCaseWordArray(String text)
    {
        if(text == null || text.length() == 0)
            return new String[0];
        ArrayList wordList = new ArrayList();
        BreakIterator boundary = BreakIterator.getWordInstance();
        boundary.setText(text);
        int start = 0;
        for(int end = boundary.next(); end != -1; end = boundary.next())
        {
            String tmp = text.substring(start, end).trim();
            tmp = replace(tmp, "+", "");
            tmp = replace(tmp, "/", "");
            tmp = replace(tmp, "\\", "");
            tmp = replace(tmp, "#", "");
            tmp = replace(tmp, "*", "");
            tmp = replace(tmp, ")", "");
            tmp = replace(tmp, "(", "");
            tmp = replace(tmp, "&", "");
            if(tmp.length() > 0)
                wordList.add(tmp);
            start = end;
        }
 
        return (String[])wordList.toArray(new String[wordList.size()]);
    }
 
    public static final String randomString(int length)
    {
        if(length < 1)
            return null;
        char randBuffer[] = new char[length];
        for(int i = 0; i < randBuffer.length; i++)
            randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
 
        return new String(randBuffer);
    }
 
    public static final int randomInt(int number)
    {
        if(number>0)
            return randGen.nextInt(number)+1;
        else
            return 1;
    }
 
    public static final String chop(String string, int length)
    {
        if(string == null)
            return null;
        if(length <= 0)
            throw new IllegalArgumentException("Length must be > 0");
        if(string.length() <= length + 2)
        {
            return string;
        } else
        {
            StringBuffer buf = new StringBuffer(string.substring(0, length));
            buf.append("...");
            return buf.toString();
        }
    }
 
    public static final String chopAtWord(String string, int length, int minLength)
    {
        if(length < 2)
            throw new IllegalArgumentException("Length specified (" + length + ") must be > 2");
        if(minLength >= length)
            throw new IllegalArgumentException("minLength must be smaller than length");
        int sLength = string != null ? string.length() : -1;
        if(sLength < 1)
            return string;
        if(minLength != -1 && sLength < minLength)
            return string;
        if(minLength == -1 && sLength < length)
            return string;
        char charArray[] = string.toCharArray();
        if(sLength > length)
        {
            sLength = length;
            for(int i = 0; i < sLength - 1; i++)
            {
                if(charArray[i] == '\r' && charArray[i + 1] == '\n')
                    return string.substring(0, i + 1);
                if(charArray[i] == '\n')
                    return string.substring(0, i);
            }
 
            if(charArray[sLength - 1] == '\n')
                return string.substring(0, sLength - 1);
            for(int i = sLength - 1; i > 0; i--)
                if(charArray[i] == ' ')
                    return string.substring(0, i).trim();
 
        } else
        if(minLength != -1 && sLength > minLength)
        {
            for(int i = 0; i < minLength; i++)
                if(charArray[i] == ' ')
                    return string;
 
        }
        if(minLength > -1 && minLength <= string.length())
            return string.substring(0, minLength);
        else
            return string.substring(0, length);
    }
 
    public static final String chopAtWord(String string, int length)
    {
        return chopAtWord(string, length, -1);
    }
 
    public static String chopAtWordsAround(String input, String wordList[], int numChars)
    {
        if(input == null || "".equals(input.trim()) || wordList == null || wordList.length == 0 || numChars == 0)
            return "";
        String lc = input.toLowerCase();
        for(int i = 0; i < wordList.length; i++)
        {
            int pos = lc.indexOf(wordList[i]);
            if(pos > -1)
            {
                int beginIdx = pos - numChars;
                if(beginIdx < 0)
                    beginIdx = 0;
                int endIdx = pos + numChars;
                if(endIdx > input.length() - 1)
                    endIdx = input.length() - 1;
                char chars[];
                for(chars = input.toCharArray(); beginIdx > 0 && chars[beginIdx] != ' ' && chars[beginIdx] != '\n' && chars[beginIdx] != '\r'; beginIdx--);
                for(; endIdx < input.length() && chars[endIdx] != ' ' && chars[endIdx] != '\n' && chars[endIdx] != '\r'; endIdx++);
                return input.substring(beginIdx, endIdx);
            }
        }
 
        return input.substring(0, input.length() < 200 ? input.length() : 200);
    }
 
    public static final String highlightWords(String string, String words[], String startHighlight, String endHighlight)
    {
        if(string == null || words == null || startHighlight == null || endHighlight == null)
            return null;
        StringBuffer regexp = new StringBuffer();
        regexp.append("(?i)\\b(");
        for(int x = 0; x < words.length; x++)
        {
            words[x] = words[x].replaceAll("([\\$\\?\\|\\/\\.])", "\\\\$1");
            regexp.append(words[x]);
            if(x != words.length - 1)
                regexp.append("|");
        }
 
        regexp.append(")");
        return string.replaceAll(regexp.toString(), startHighlight + "$1" + endHighlight);
    }
 
    public static final String escapeForSQL(String string)
    {
        if(string == null)
            return null;
        if(string.length() == 0)
            return string;
        char input[] = string.toCharArray();
        int i = 0;
        int last = 0;
        int len = input.length;
        StringBuffer out = null;
        for(; i < len; i++)
        {
            char ch = input[i];
            if(ch != '\'')
                continue;
            if(out == null)
                out = new StringBuffer(len + 2);
            if(i > last)
                out.append(input, last, i - last);
            last = i + 1;
            out.append('\'').append('\'');
        }
 
        if(out == null)
            return string;
        if(i > last)
            out.append(input, last, i - last);
        return out.toString();
    }
 
    public static final String escapeForXML(String string)
    {
        if(string == null)
            return null;
        int i = 0;
        int last = 0;
        char input[] = string.toCharArray();
        int len = input.length;
        StringBuffer out = new StringBuffer((int)((double)len * 1.3D));
        for(; i < len; i++)
        {
            char ch = input[i];
            if(ch > '>')
                continue;
            if(ch == '<')
            {
                if(i > last)
                    out.append(input, last, i - last);
                last = i + 1;
                out.append(LT_ENCODE);
                continue;
            }
            if(ch == '>')
            {
                if(i > last)
                    out.append(input, last, i - last);
                last = i + 1;
                out.append(GT_ENCODE);
                continue;
            }
            if(ch == '&')
            {
                if(i > last)
                    out.append(input, last, i - last);
                last = i + 1;
                out.append(AMP_ENCODE);
                continue;
            }
            if(ch == '"')
            {
                if(i > last)
                    out.append(input, last, i - last);
                last = i + 1;
                out.append(QUOTE_ENCODE);
                continue;
            }
            if(ch == '\n' || ch == '\r' || ch == '\t' || ch >= ' ')
                continue;
            if(i > last)
                out.append(input, last, i - last);
            last = i + 1;
        }
 
        if(last == 0)
            return string;
        if(i > last)
            out.append(input, last, i - last);
        return out.toString();
    }
 
    public static final String unescapeFromXML(String string)
    {
        string = replace(string, "<", "<");
        string = replace(string, ">", ">");
        string = replace(string, """, "\"");
        return replace(string, "&", "&");
    }
 
    public static final String zeroPadString(String string, int length)
    {
        if(string == null || string.length() > length)
        {
            return string;
        } else
        {
            StringBuffer buf = new StringBuffer(length);
            buf.append(zeroArray, 0, length - string.length()).append(string);
            return buf.toString();
        }
    }
 
    public static final String Encode(String input,String encode){
      if(input==null || "".equals(input)) return input;
      try {
        return new String(input.getBytes("iso-8859-1"), encode);
      }
      catch (UnsupportedEncodingException ex) {
        return "";
      }
    }
 
    public static final String getFileExtName(String filename)
    {
        String ext = "";
        int p = filename.lastIndexOf(".");
        if (p != -1)
        {
            ext = filename.substring(p + 1, filename.length());
        }
        return ext.toLowerCase();
    }
 
    public static final String getPath(long id)
    {
        String returnStr = "";
        char charArray[] = String.valueOf(id).toCharArray();
        int j = charArray.length;
        for (int i = 0; i < j; i++)
        {
            returnStr += charArray[i] + File.separator;
        }
        return returnStr;
    }
 
    public static final String getUrlPath(long id)
    {
        String returnStr = "";
        char charArray[] = String.valueOf(id).toCharArray();
        int j = charArray.length;
        for (int i = 0; i < j; i++)
        {
            returnStr += charArray[i] + "/";
        }
        return returnStr;
    }
 
    public static final String dateToMillis(Date date)
    {
      return "";
        /*if(ConnectionManager.getDateType() == 12)
            return zeroPadString(Long.toString(date.getTime()), 15);
        else
            return Long.toString(date.getTime());*/
    }
 
    /**
     * @param len 需要显½Cºçš„长度(<font color="red">注意åQšé•¿åº¦æ˜¯ä»¥byte为单位的åQŒä¸€ä¸ªæ±‰å­—是2个byte</font>)
     * @param symbol 用于表示省略的信息的字符åQŒå¦‚â€?..â€?â€?gt;>>”等ã€?br />     * @return ˜q”回处理后的字符ä¸?br />     */
    public static String getLimitLengthString(String str,int len, String symbol) throws
            UnsupportedEncodingException
    {
        if(str==null || "".equals(str)) return str;
        int counterOfDoubleByte;
        byte b[];
        counterOfDoubleByte = 0;
        b = str.getBytes("GBK");
        if (b.length <= len)
            return str;
        for (int i = 0; i < len; i++)
        {
            if (b[i] < 0)
                counterOfDoubleByte++;
        }
 
        if (counterOfDoubleByte % 2 == 0)
            return new String(b, 0, len, "GBK") + symbol;
        else
            return new String(b, 0, len - 1, "GBK") + symbol;
    }
 
 
    public static boolean isValidEmailAddress(String addr)
    {
        if(addr == null)
            return false;
        addr = addr.trim();
        if(addr.length() == 0)
            return false;
        Matcher matcher = basicAddressPattern.matcher(addr);
        if(!matcher.matches())
            return false;
        String userPart = matcher.group(1);
        String domainPart = matcher.group(2);
        matcher = validUserPattern.matcher(userPart);
        if(!matcher.matches())
            return false;
        matcher = ipDomainPattern.matcher(domainPart);
        if(matcher.matches())
        {
            for(int i = 1; i < 5; i++)
            {
                String num = matcher.group(i);
                if(num == null)
                    return false;
                if(Integer.parseInt(num) > 254)
                    return false;
            }
 
            return true;
        }
        matcher = domainPattern.matcher(domainPart);
        if(matcher.matches())
        {
            String tld = matcher.group(matcher.groupCount());
            matcher = tldPattern.matcher(tld);
            return tld.length() == 3 || matcher.matches();
        } else
        {
            return false;
        }
    }
 
    /**
     * 判断是否为数字组成的字串
     * @param validString 要判断的字符ä¸?br />     * @return boolenå€û|¼Œtrue或false
     */
    public static boolean isNumber(String validString){
      try
      {
        if (validString == null)
          return false;
        byte[] tempbyte = validString.getBytes();
        for (int i = 0; i < validString.length(); i++) {
          //by=tempbyte[i];
          if ( (tempbyte[i] < 48) || (tempbyte[i] > 57)) {
            return false;
          }
        }
        return true;
      }
      catch(Exception ex)
      {
        return false;
      }
  }
 
    private static final char QUOTE_ENCODE[] = """.toCharArray();
    private static final char AMP_ENCODE[] = "&".toCharArray();
    private static final char LT_ENCODE[] = "<".toCharArray();
    private static final char GT_ENCODE[] = ">".toCharArray();
    private static Pattern basicAddressPattern;
    private static Pattern validUserPattern;
    private static Pattern domainPattern;
    private static Pattern ipDomainPattern;
    private static Pattern tldPattern;
    private static MessageDigest digest = null;
    private static final char CA[];
    private static final int IA[];
    private static final BitSet allowed_query;
    private static Random randGen = new Random();
    private static char numbersAndLetters[] = "0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    private static final char zeroArray[] = "0000000000000000000000000000000000000000000000000000000000000000".toCharArray();
    private static MD5 md5 = new MD5();
 
    static
    {
        String basicAddress = "^([\\w\\.-]+)@([\\w\\.-]+)$";
        String specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
        String validChars = "[^ \f\n\r\t" + specialChars + "]";
        String atom = validChars + "+";
        String quotedUser = "(\"[^\"]+\")";
        String word = "(" + atom + "|" + quotedUser + ")";
        String validUser = "^" + word + "(\\." + word + ")*$";
        String domain = "^" + atom + "(\\." + atom + ")+$";
        String ipDomain = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$";
        String knownTLDs = "^\\.(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$";
        basicAddressPattern = Pattern.compile(basicAddress, 2);
        validUserPattern = Pattern.compile(validUser, 2);
        domainPattern = Pattern.compile(domain, 2);
        ipDomainPattern = Pattern.compile(ipDomain, 2);
        tldPattern = Pattern.compile(knownTLDs, 2);
        CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
        IA = new int[256];
        Arrays.fill(IA, -1);
        int i = 0;
        for(int iS = CA.length; i < iS; i++)
            IA[CA[i]] = i;
 
        IA[61] = 0;
        allowed_query = new BitSet(256);
        for(i = 48; i <= 57; i++)
            allowed_query.set(i);
 
        for(i = 97; i <= 122; i++)
            allowed_query.set(i);
 
        for(i = 65; i <= 90; i++)
            allowed_query.set(i);
 
        allowed_query.set(45);
        allowed_query.set(95);
        allowed_query.set(46);
        allowed_query.set(33);
        allowed_query.set(126);
        allowed_query.set(42);
        allowed_query.set(39);
        allowed_query.set(40);
        allowed_query.set(41);
 
 
    }
}



]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º ¶·ÁùÊÐ| ¼Ó²éÏØ| °Í¶«ÏØ| ÎàÖÝÊÐ| °²ÈÊÏØ| ÎäÐûÏØ| Í©³ÇÊÐ| аͶû»¢×óÆì| ÜõÍåÇø| ÐûÎäÇø| ¹ó¶¨ÏØ| Ì«¹ÈÏØ| ·ïÏèÏØ| ½ð»ªÊÐ| ½£ºÓÏØ| ɳÌïÇø| ʯ³ÇÏØ| ÓÀÊ¤ÏØ| Óý¶ù| Ã÷Ë®ÏØ| ´óÒ±ÊÐ| Î÷²ýÊÐ| ¸ñ¶ûľÊÐ| ÄÏÑôÊÐ| Â«É½ÏØ| Ç­Î÷ÏØ| µÀæÚÏØ| ÉñÄ¾ÏØ| Î÷²Ø| ÂåÄþÏØ| ½£ºÓÏØ| ÃÖÀÕÏØ| µæ½­ÏØ| ±±º£ÊÐ| ËÞǨÊÐ| ̨ÖÐÊÐ| ÑôÐÂÏØ| ½ðËþÏØ| ×ÞÆ½ÏØ| Çå½§ÏØ| ½¹×÷ÊÐ|