国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

一個(gè)進(jìn)行Base64編碼的類

2019-11-18 15:19:20
字體:
供稿:網(wǎng)友

  作者:sonymusic
email: sonymusic@china.com
日期:2001-3-12 15:01:35
package sony.utils;

import java.io.*;
import java.net.*;
public final class Codes {
public final static byte[] base64Encode(byte[] byteData) {
if (byteData == null)
return null;
int iSrcIdx; // index into source (byteData)
int iDestIdx; // index into destination (byteDest)
byte byteDest[] = new byte[((byteData.length + 2) / 3) * 4];

for (iSrcIdx = 0, iDestIdx = 0; iSrcIdx < byteData.length - 2; iSrcIdx += 3) {
byteDest[iDestIdx++] = (byte) ((byteData[iSrcIdx] >>> 2) & 077);
byteDest[iDestIdx++] =
(byte) ((byteData[iSrcIdx + 1] >>> 4) & 017 (byteData[iSrcIdx] << 4) & 077);
byteDest[iDestIdx++] =
(byte) ((byteData[iSrcIdx + 2] >>> 6)
& 003
(byteData[iSrcIdx + 1] << 2)
& 077);
byteDest[iDestIdx++] = (byte) (byteData[iSrcIdx + 2] & 077);
}

if (iSrcIdx < byteData.length) {
byteDest[iDestIdx++] = (byte) ((byteData[iSrcIdx] >>> 2) & 077);
if (iSrcIdx < byteData.length - 1) {
byteDest[iDestIdx++] =
(byte) ((byteData[iSrcIdx + 1] >>> 4) & 017 (byteData[iSrcIdx] << 4) & 077);
byteDest[iDestIdx++] = (byte) ((byteData[iSrcIdx + 1] << 2) & 077);
} else
byteDest[iDestIdx++] = (byte) ((byteData[iSrcIdx] << 4) & 077);
}

for (iSrcIdx = 0; iSrcIdx < iDestIdx; iSrcIdx++) {
if (byteDest[iSrcIdx] < 26)
byteDest[iSrcIdx] = (byte) (byteDest[iSrcIdx] + ´A´);
else
if (byteDest[iSrcIdx] < 52)
byteDest[iSrcIdx] = (byte) (byteDest[iSrcIdx] + ´a´ - 26);
else
if (byteDest[iSrcIdx] < 62)
byteDest[iSrcIdx] = (byte) (byteDest[iSrcIdx] + ´0´ - 52);
else
if (byteDest[iSrcIdx] < 63)
byteDest[iSrcIdx] = (byte) ´+´;
else
byteDest[iSrcIdx] = (byte) ´/´;
}

for (; iSrcIdx < byteDest.length; iSrcIdx++)
byteDest[iSrcIdx] = (byte) ´=´;

return byteDest;
}
public final static String base64Encode(String strInput) {
if (strInput == null)
return null;
return base64Encode(strInput,"GB2312");
}
public final static String base64Encode(String strInput,String charSet) {
if (strInput == null)
return null;
String strOutput=null;
byte byteData[] = new byte[strInput.length()];
try {
//strInput.getBytes(0, strInput.length(), byteData, 0);
byteData = strInput.getBytes(charSet);
strOutput=new String(base64Encode(byteData),charSet);
//strOutput=new String(base64Encode(byteData),0);
} catch (UnsupportedEncodingException e) {
return null;
}
return strOutput;
}
/**
* 此處插入方法說明。
* 創(chuàng)建日期:(2000-11-4 18:27:35)
* @param steam java.io.InputStream
* @param charSet java.lang.String
*/
public final static String base64Encode(InputStream in, String charSet) {
try {
int c;
byte[] buff = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
while ((c = in.read(buff, 0, 1024)) != -1) {
out.write(buff, 0, c);
//index+=1024;
//out.write(c);
//attachContent+=ss;
}
in.close();
out.flush();
byte[] tmp2 = Codes.base64Encode(out.toByteArray());
out.close();
return new String(tmp2,charSet);
}
catch (IOException e) {
return "";
}
}/**
* 此處插入方法說明。
* 創(chuàng)建日期:(2000-11-3 23:31:04)
* @return java.lang.String
* @param strIn java.lang.String
*/
public final static String chunkSplit(String strIn) {
return chunkSplit(strIn,76);
}/**
* 此處插入方法說明。
* 創(chuàng)建日期:(2000-11-3 23:31:04)
* @return java.lang.String
* @param strIn java.lang.String
*/
public final static String chunkSplit(String strIn,int splitLen) {
int index=0;
String strOut="";
while(index+splitLen<strIn.length()){
strOut+=strIn.substring(index,index+splitLen)+"";
index+=splitLen;
}
if(index<strIn.length()){
strOut+=strIn.substring(index);
}
return strOut;
}
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 五指山市| 鄂伦春自治旗| 石泉县| 孙吴县| 米易县| 文昌市| 电白县| 稷山县| 班戈县| 香港| 澄迈县| 文山县| 大连市| 寻乌县| 彭水| 泰宁县| 郧西县| 威信县| 子长县| 伊吾县| 乌什县| 岳普湖县| 石林| 尚义县| 长武县| 象州县| 鹤岗市| 华池县| 邛崃市| 东丽区| 来宾市| 台中县| 鄄城县| 逊克县| 和政县| 丘北县| 于都县| 读书| 潞西市| 耒阳市| 通辽市|