base64 编解码的 Java 实现
/**
* Base64Util for Java
* cheungmine
* 2009-11-8
*/
public class Base64Util {
/**
* @param args
*/
public static void main(String[] args)
{
// 源字节数组
int cb = 0;
System.out.print("源字节数组: ");
byte in[] = new byte[100];
in[cb++]='1';
in[cb++]='2';
in[cb++]='3';
in[cb++]='4';
in[cb++]='5';
System.out.write(in, 0, cb);
// 计算编码需要的输出字节尺寸
int cbOut = encodeString( in, cb, null, 0);
// 为输出分配数组
byte out[] = new byte[cbOut];
// 开始编码
encodeString( in, cb, out, 0);
// 输出编码内容
System.out.print("\n编码后内容: ");
System.out.write(out, 0, cbOut);
// 计算解码需要的字节
int cbDec = decodeString(out, cbOut, null);
// 分配解码数组
byte dec[] = new byte[cbDec];
// 开始解码
decodeString(out, cbOut, dec);
// 输出解码结果, 这个结果和输出应该一致
System.out.print("\n解码的结果: ");
System.out.write(dec, 0, cbDec);
}
/**
* Translation Table as described in RFC1113
*/
static String cb64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* Translation Table to decode (created by author)
*/
static String cd64="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
/**
* encodeBlock
*
* encode 3 8-bit binary bytes (in) as 4 '6-bit' characters (out)
*/
static void encodeBlock( byte in[], byte out[], int len )
{
out[0] = (byte) cb64.charAt( in[0] >> 2 );
out[1] = (byte) cb64.charAt( ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) );
out[2] = (byte) (len > 1 ? cb64.charAt( ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ) : '=');
out[3] = (byte) (len > 2 ? cb64.charAt( in[2] & 0x3f ) : '=');
}
/**
* decodeBlock
*
* decode 4 '6-bit' characters into 3 8-bit binary bytes
*/
相关文档:
1. 如果已经知道某个地点的时区,年,月,日,时,分,秒,希望得到转换后的本系统时间,可以采用如下的方法:
方法:假设时区是GMT+08:00,,年是2009年,月是11月,日是7日,时是10时,分是50分,秒是30。
public class Time {
public static void main(String[] args) {
TimeZone tz = Tim ......
package sample1;
import java.io.File;
import jp.ne.so_net.ga2.no_ji.jcom.IDispatch;
import jp.ne.so_net.ga2.no_ji.jcom.JComException;
import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
/**
* 使用jCom实现写excel文件的另一种方式(IDispatch)
* @author steve_wang_victor
&nbs ......
1.接口与抽象类区别
abstract class 在 Java 语言中表示的是一种继承关系,一个类只能使用一次继承关系。但是,一个类却可以实现多个interface。
在abstract class 中可以有自己的数据成员,也可以有非abstarct的成员方法,而在interface中,只能够有静态的不能被修改的数据成员 ......
/*****************TestCar1 begin************************/
public class TestCar1 {
public static final int Ok=1; //正常情况
public static final int Wrong=2; //异常情况
public int run(){
if("车子没有出现故障"){  ......