base64µÄjavaʵÏÖ·½·¨
package cn.eshore.mismp.sms.ws.send;
public class Base64 {
/**
* ½«ÔʼÊý¾Ý±àÂëΪbase64±àÂë
*/
static public char[] encode(byte[] data) {
char[] out = new char[((data.length + 2) / 3) * 4];
for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
boolean quad = false;
boolean trip = false;
int val = (0xFF & (int) data[i]);
val <<= 8;
if ((i + 1) < data.length) {
val |= (0xFF & (int) data[i + 1]);
trip = true;
}
val <<= 8;
if ((i + 2) < data.length) {
val |= (0xFF & (int) data[i + 2]);
quad = true;
}
out[index + 3] = alphabet[(quad ? (val & 0x3F) : 64)];
val >>= 6;
out[index + 2] = alphabet[(trip ? (val & 0x3F) : 64)];
val >>= 6;
out[index + 1] = alphabet[val & 0x3F];
val >>= 6;
out[index + 0] = alphabet[val & 0x3F];
}
return out;
}
/**
* ½«base64±àÂëµÄÊý¾Ý½âÂë³ÉÔʼÊý¾Ý
*/
static public byte[] decode(char[] data) {
int len = ((data.length + 3) / 4) * 3;
if (data.length > 0 && data[data.length - 1] == '=')
--len;
if (data.length > 1 && data[data.length - 2] == '=')
--len;
byte[] out = new byte[len];
int shift = 0;
int accum = 0;
int index = 0;
for (int ix = 0; ix < data.length; ix++) {
int value = codes[data[ix] & 0xFF];
if (value >= 0) {
accum <<= 6;
shift += 6;
accum |= value;
if (shift >= 8) {
shift -= 8;
out[index++] = (byte) ((accum >> shift) & 0xff);
}
}
}
if (index != out.length)
throw new Error("miscalculated data length!");
return out;
}
static private char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
.toCharArray();
static private byte[] codes = new byte[256];
static {
for (int i = 0; i < 256; i++)
codes[i] = -1;
for (int i = 'A'; i <= 'Z'; i++)
codes[i] =
Ïà¹ØÎĵµ£º
ת[http://hi.baidu.com/ge_star/blog/item/8b23b210f8066f08203f2e90.html]
1.°üÃüÃû:È«²¿×ÖĸСд:cn.package.bean
2.ÀàÃüÃû:µ¥´ÊµÄÊ××Öĸ´óд:SimpleBean
3.ÊôÐÔÃû³Æ:µÚÒ»¸öµ¥´ÊµÄÊ××ÖĸСд,Ö®ºóÿ¸öµ¥´ÊµÄÊ××Öĸ´óдstudentName
4.·½·¨ÃüÃû:ÓëÊôÐÔÃüÃûÏàͬ:public void sayHello()
5.³ ......
ÔÚjavaÈç¹ûÒ»¸ö³ÉÔ±±»ÉùÃ÷Ϊstatic£¬Ëü¾ÍÄܹ»ÔÚËüµÄÀàµÄÈκζÔÏó´´½¨Ö®Ç°±»·ÃÎÊ£¬¶ø²»±ØÒýÓÃÈκζÔÏó¡£Äã¿ÉÒÔ½«·½·¨ºÍ±äÁ¿¶¼ÉùÃ÷Ϊstatic¡£static ³ÉÔ±µÄ×î³£¼ûµÄÀý×ÓÊÇmain( ) ¡£ÒòΪÔÚ³ÌÐò¿ªÊ¼Ö´ÐÐʱ±ØÐëµ÷ÓÃmain() £¬ËùÒÔËü±»ÉùÃ÷Ϊstatic¡£
ÓÐʱÄãÏ£Íû¶¨ÒåÒ»¸öÀà³ÉÔ±£¬Ê¹ËüµÄʹÓÃÍêÈ«¶ÀÁ¢ÓÚ¸ÃÀàµÄÈκζÔÏó¡£Í¨³ ......
·´ÉäʹÄúµÄ³ÌÐò´úÂëÄܹ»½ÓÈë×°Ôص½JVMÖеÄÀàµÄÄÚ²¿ÐÅÏ¢£¬ÔÊÐíÄú±àдÓëÖ´ÐÐʱ£¬¶ø²»ÊÇÔ´´úÂëÖÐÑ¡¶¨µÄÀàÐ×÷µÄ´úÂë¡£Õâʹ·´Éä³É
Ϊ¹¹½¨Áé»îµÄÓ¦ÓõÄÖ÷Òª¹¤¾ß¡£µ«Ðè×¢ÒâµÄÊÇ --Èç¹ûʹÓò»µ±£¬·´ÉäµÄ³É±¾ºÜ¸ß¡£ÔÚJavaƽ̨ϵÁеĵÚ2²¿·ÖÖУ¬Èí¼þ¹ËÎÊDennis
Sosnoski½éÉÜÁËÈçºÎʹÓ÷´É䣬ÒÔ¼°Ä³Ð©Ïà¹ØµÄ³É±¾¡£Äú»¹½«ÕÒµ½JavaRef ......
ÉÏѧʱºÜ¶àÎÊÌâµÄ´ð°¸£¬¿ÉÒÔ´ÓÏÂÎÄÕÒµ½
JAVAÓïÑÔѧУµÄΣÏÕÐÔ
×÷ÕߣºJoel Spolsky
ÒëÕߣºÈîÒ»·å
ÔÎÄ£º http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html
ÒëÎĵØÖ·£ºhtt ......
1¡¢http://java.sun.com/
(Ó¢ÎÄ)
SunµÄJavaÍøÕ¾£¬ÊÇÒ»¸öÓ¦¸Ã¾³£È¥¿´µÄµØ·½¡£²»Óöà˵¡£
2¡¢http://www-900.ibm.com/developerWorks/cn/
IBMµÄdeveloperWorksÍøÕ¾£¬Ó¢ÓïºÃµÄÖ±½ÓÈ¥Ó¢ÎÄÖ÷Õ¾µã¿´¡£ÕâÀï²»µ«ÊÇÒ»¸ö¼«ºÃµÄÃæÏò¶ÔÏóµÄ·ÖÎöÉè¼ÆÍøÕ¾£¬Ò²ÊÇWebServices£¬Java£¬Linux¼«ºÃµÄÍøÕ¾¡£Ç¿ÁÒÍƼö£¡£¡£¡
3¡¢http://www.j ......