Java实现的utf8 gbk unic ode编码相互转换的代码public static String GBK2Unicode(String str) {
StringBuffer result=new StringBuffer();for(int i=0; i s tr.length(); i++) {c har c hr 1=(c har) str.c harAt(i);if(!isNeedConvert(chr 1)) {result.append(chr 1);c ontinue;result.append( \\u+Integer.toHexString((int)c hr 1));return result.toString();
*@param dataStr
*@return Stringpublic static String Unicode2GBK(String dataStr) {int index=0;
StringBuffer buffer=new StringBuffer();int li_len=dataStr.length();while(index li_len) {if(index=li_len- 1
| | ! \\u.equals(dataStr.subs tring(index, index+2))) {buffer.append(dataStr.charAt(index));index++;c ontinue;
String charStr=
charStr=dataStr.substring(index+2, index+6);char letter=(char) Integer.pars eInt(charStr, 16);buffer.app end(letter);index+=6;return buffer.toString();public static boolean isNeedConvert(char para) {r eturn((p ar a(0 x 00 F F)) !=p ar a);
*utf-8转unic ode
*@param inStr
*@return Stringpublic static String utf8ToUnicode(String inStr) {c har[]myBuffer=inStr.toCharArray();
StringBuffer sb=new StringBuffer();for(int i=0; i inStr.length(); i++) {
UnicodeBlock ub=UnicodeBlock.of(myBuffer[i]);if(ub==UnicodeBlock.BASIC_LATIN) {sb.append(myBuffer[i]);
} else if(ub==UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {int j=(int)myBuffer[i] -65248;sb.append((char)j);
} els e {short s=(short)myBuffer[i];
String hexS=Integer.toHexString(s);
String unicode=\\u+hexS;sb.append(unic ode.toLow erCas e());return sb.toString();
*@param theString
*@return Stringpublic static String unicodeToUtf8(String theString) {char aChar;int len=theString.length();
String Buffer outBuffer=new StringBuffer(len);for(int x=0;x len;) {aChar=theS tring.c harAt(x++);if(aChar==‘\\’) {aChar=theS tring.c harAt(x++);if(aChar==‘u’) {
//Read the xxxxint value=0;for(int i=0; i i++) {aChar=theS tring.c harAt(x++);sw itc h(aChar) {case ‘0’ :case ‘1’ :
case ‘2’ :case ‘3’ :case ‘4’ :case ‘5’ :case ‘6’ :case ‘7’ :case ‘8’ :case ‘9’ :value=(value 4)+aChar- ‘0’ ;break;case ‘a’ :case ‘b’ :case ‘c’ :case ‘d’ :case ‘e’ :case ‘f’ :value=(value 4)+10+aChar- ‘a’ ;break;case ‘A’ :case ‘B’ :case ‘C’ :case ‘D’ :
case ‘E’ :case ‘F’ :value=(value 4)+10+aChar- ‘A’ ;break;default:throw new IllegalArgumentExc eption(Malformed\\uxxxx enc oding.outBuffer.append((c har)value);
} els e {if(aChar==‘t’)aChar=‘\t’ ;els e if(aChar==‘r’)aChar=‘\r’ ;els e if(aChar==‘n’)aChar=‘\n’ ;els e if(aChar==‘f’)aChar=‘\f’ ;outBuffer.app end(aChar);
} els eoutBuffer.app end(aChar);return outBuffer.to String();
}
IMIDC是一家香港本土运营商,商家名为彩虹数据(Rainbow Cloud),全线产品自营,自有IP网络资源等,提供的产品包括VPS主机、独立服务器、站群独立服务器等,数据中心区域包括香港、日本、台湾、美国和南非等地机房,CN2网络直连到中国大陆。目前主机商针对日本独立服务器做促销活动,而且提供/28 IPv4,国内直连带宽优惠后每月仅88美元起。JP Multiple IP Customize...
最近很多网站都遭受到了伪墙/假墙攻击,导致网站流量大跌,间歇性打不开网站。这是一种新型的攻击方式,攻击者利用GWF规则漏洞,使用国内服务器绑定host的方式来触发GWF的自动过滤机制,造成GWF暂时性屏蔽你的网站和服务器IP(大概15分钟左右),使你的网站在国内无法打开,如果攻击请求不断,那么你的网站就会是一个一直无法正常访问的状态。常规解决办法:1,快速备案后使用国内服务器,2,使用国内免备案服...
GigsGigsCloud是一家成立于2015年老牌国外主机商,提供VPS主机和独立服务器租用,数据中心包括美国洛杉矶、中国香港、新加坡、马来西亚和日本等。商家VPS主机基于KVM架构,绝大部分系列产品中国访问速度不错,比如洛杉矶机房有CN2 GIA、AS9929及高防线路等。目前Los Angeles - SimpleCloud with Premium China DDOS Protectio...