欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
J2ME經(jīng)驗總結之Base64(
J2ME經(jīng)驗總結之Base64(
作者:佚名    文章來(lái)源:索愛(ài)開(kāi)發(fā)社區    點(diǎn)擊數:59    更新時(shí)間:2008-2-29
Base64內容傳送編碼被設計用來(lái)把任意序列的8位字節描述為一種不易被人直接識別的形式。(The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable.)

Base64是網(wǎng)絡(luò )上最常見(jiàn)的用于傳輸8Bit字節代碼的編碼方式之一,在發(fā)送電子郵件時(shí),服務(wù)器認證的用戶(hù)名和密碼需要用Base64編碼,附件也需要用Base64編碼……

下面是以前扒來(lái)的MD5算法的JAVA版本,J2ME可以放心使用。
package hlib;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;

public class HBase64 {

private static final char[] legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
.toCharArray();

private static Vector nodes = new Vector();

/**
* Split string into multiple strings
*
* @param original
* Original string
* @param separator
* Separator string in original string
* @return Splitted string array
*/
public static String[] split(String original, String separator) {
nodes.removeAllElements();
// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement(original);

// Create splitted string array
String[] result = new String[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++)
result[loop] = (String) nodes.elementAt(loop);
}
return result;
}

/*
* Replace all instances of a String in a String. @param s String to alter.
* @param f String to look for. @param r String to replace it with, or null
* to just remove it.
*/
public static String replace(String s, String f, String r) {
if (s == null)
return s;
if (f == null)
return s;
if (r == null)
r = "";

int index01 = s.indexOf(f);
while (index01 != -1) {
s = s.substring(0, index01) + r + s.substring(index01 + f.length());
index01 += r.length();
index01 = s.indexOf(f, index01);
}
return s;
}

/**
* Method removes HTML tags from given string.
*
* @param text
* Input parameter containing HTML tags (eg. <b>cat</b>)
* @return String without HTML tags (eg. cat)
*/
public static String removeHtml(String text) {
try {
int idx = text.indexOf("<");
if (idx == -1)
return text;

String plainText = "";
String htmlText = text;
int htmlStartIndex = htmlText.indexOf("<", 0);
if (htmlStartIndex == -1) {
return text;
}
while (htmlStartIndex >= 0) {
plainText += htmlText.substring(0, htmlStartIndex);
int htmlEndIndex = htmlText.indexOf(">", htmlStartIndex);
htmlText = htmlText.substring(htmlEndIndex + 1);
htmlStartIndex = htmlText.indexOf("<", 0);
}
plainText = plainText.trim();
return plainText;
} catch (Exception e) {
System.err.println("Error while removing HTML: " + e.toString());
return text;
}
}

/** Base64 encode the given data */
public static String encode(byte[] data) {
int start = 0;
int len = data.length;
StringBuffer buf = new StringBuffer(data.length * 3 / 2);

int end = len - 3;
int i = start;
int n = 0;

while (i <= end) {
int d = ((((int) data) & 0x0ff) << 16)
| ((((int) data[i + 1]) & 0x0ff) << 8)
| (((int) data[i + 2]) & 0x0ff);

buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append(legalChars[d & 63]);

i += 3;

if (n++ >= 14) {
n = 0;
buf.append(" ");
}
}

if (i == start + len - 2) {
int d = ((((int) data) & 0x0ff) << 16)
| ((((int) data[i + 1]) & 255) << 8);

buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append("=");
} else if (i == start + len - 1) {
int d = (((int) data) & 0x0ff) << 16;

buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append("==");
}

return buf.toString();
}

private static int decode(char c) {
if (c >= 'A' && c <= 'Z')
return ((int) c) - 65;
else if (c >= 'a' && c <= 'z')
return ((int) c) - 97 + 26;
else if (c >= '0' && c <= '9')
return ((int) c) - 48 + 26 + 26;
else
switch (c) {
case '+':
return 62;
case '/':
return 63;
case '=':
return 0;
default:
throw new RuntimeException("unexpected code: " + c);
}
}

/**
* Decodes the given Base64 encoded String to a new byte array. The byte
* array holding the decoded data is returned.
*/

public static byte[] decode(String s) {

ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
decode(s, bos);
} catch (IOException e) {
throw new RuntimeException();
}
byte[] decodedBytes = bos.toByteArray();
try {
bos.close();
bos = null;
} catch (IOException ex) {
System.err.println("Error while decoding BASE64: " + ex.toString());
}
return decodedBytes;
}

private static void decode(String s, OutputStream os) throws IOException {
int i = 0;

int len = s.length();

while (true) {
while (i < len && s.charAt(i) <= ' ')
i++;

if (i == len)
break;

int tri = (decode(s.charAt(i)) << 18)
+ (decode(s.charAt(i + 1)) << 12)
+ (decode(s.charAt(i + 2)) << 6)
+ (decode(s.charAt(i + 3)));

os.write((tri >> 16) & 255);
if (s.charAt(i + 2) == '=')
break;
os.write((tri >> 8) & 255);
if (s.charAt(i + 3) == '=')
break;
os.write(tri & 255);

i += 4;
}
}
}
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Android、iPhone和Java三個(gè)平臺一致的加密工具
一個(gè)給代碼作高亮度彩色處理的類(lèi)
SpringMVC+Apache Shiro+JPA(hibernate)案例教學(xué)(三)給Shiro登錄驗證加上驗證碼
關(guān)于JSP靜態(tài)化與偽靜態(tài)的簡(jiǎn)單做法
【Java字符串】字符串雖簡(jiǎn)單,但這些你不一定知道【小白一定要注意】
UUID做主鍵,優(yōu)點(diǎn),缺點(diǎn)!
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久