- 浏览: 53427 次
- 性别:
- 来自: 深圳
最新评论
-
wanglu271991027:
改成4.3也不能下啊
jBPM 4 Maven Dependencies -
liangfeng366:
怎么我的下不下来呢。。
1-5-24 下午03时23分23秒: ...
jBPM 4 Maven Dependencies -
makemyownlife:
恩 最近也在看这个方面的东东 好
ibatis3 Configuration -
magibt:
后面两个改成4.3吧
jBPM 4 Maven Dependencies -
magibt:
good job
jBPM 4 Maven Dependencies
class MyEncoding { public static string EncodeUtf8ByteToString(byte[] buffer) { int count = 0; int index = 0; byte a = 0; int utfLength = buffer.Length; char[] result = new char[utfLength]; while (count < utfLength) { if ((result[index] = (char)buffer[count++]) < 0x80) { index++; } else if (((a = (byte)result[index]) & 0xE0) == 0xC0) { if (count >= utfLength) { throw new IOException("Invalid UTF-8 encoding found, start of two byte char found at end."); } byte b = buffer[count++]; if ((b & 0xC0) != 0x80) { throw new IOException( "Invalid UTF-8 encoding found, byte two does not start with 0x80."); } result[index++] = (char)(((a & 0x1F) << 6) | (b & 0x3F)); } else if ((a & 0xF0) == 0xE0) { if (count + 1 >= utfLength) { throw new IOException( "Invalid UTF-8 encoding found, start of three byte char found at end."); } byte b = buffer[count++]; byte c = buffer[count++]; if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) { throw new IOException( "Invalid UTF-8 encoding found, byte two does not start with 0x80."); } result[index++] = (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F)); } else { throw new IOException("Invalid UTF-8 encoding found, aborting."); } } return new String(result, 0, index); ; } /// <summary> /// Method ReadString /// </summary> /// <returns>A string</returns> public static String ReadString(byte[] bytearr) { int utflen = bytearr.Length; if (utflen > -1) { StringBuilder str = new StringBuilder(utflen); //byte[] bytearr = new byte[utflen]; //int bytesRead = 0; //while (bytesRead < utflen) //{ // int rc = Read(bytearr, bytesRead, utflen - bytesRead); // if (rc == 0) // throw new IOException("premature end of stream"); // bytesRead += rc; //} int c, char2, char3; int count = 0; while (count < utflen) { c = bytearr[count] & 0xff; switch (c >> 4) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: /* 0xxxxxxx */ count++; str.Append((char)c); break; case 12: case 13: /* 110x xxxx 10xx xxxx */ count += 2; if (count > utflen) { throw new IOException("Invalid UTF-8 encoding found, aborting."); } char2 = bytearr[count - 1]; if ((char2 & 0xC0) != 0x80) { throw new IOException("Invalid UTF-8 encoding found, aborting."); } str.Append((char)(((c & 0x1F) << 6) | (char2 & 0x3F))); break; case 14: /* 1110 xxxx 10xx xxxx 10xx xxxx */ count += 3; if (count > utflen) { throw new IOException("Invalid UTF-8 encoding found, aborting."); } char2 = bytearr[count - 2]; char3 = bytearr[count - 1]; if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) { throw new IOException("Invalid UTF-8 encoding found, aborting."); } str.Append((char)(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0))); break; default: /* 10xx xxxx, 1111 xxxx */ throw new IOException("Invalid UTF-8 encoding found, aborting."); } } // The number of chars produced may be less than utflen return str.ToString(); } else { return null; } } public static byte[] EncodeStringToUtf8Byte(string text) { if (text != null) { char[] charr = text.ToCharArray(); uint utfLength = CountUtf8Bytes(charr); if (utfLength > int.MaxValue) { throw new IOException( String.Format( "Cannot marshall an encoded string longer than: {0} bytes, supplied" + "string requires: {1} characters to encode", int.MaxValue, utfLength)); } byte[] bytearr = new byte[utfLength]; EncodeUTF8toBuffer(charr, bytearr); return bytearr; } else { return new byte[0]; } } private static uint CountUtf8Bytes(char[] chars) { uint utfLength = 0; int c = 0; for (int i = 0; i < chars.Length; i++) { c = chars[i]; if ((c >= 0x0001) && (c <= 0x007F)) { utfLength++; } else if (c > 0x07FF) { utfLength += 3; } else { utfLength += 2; } } return utfLength; } private static void EncodeUTF8toBuffer(char[] chars, byte[] buffer) { int c = 0; int count = 0; for (int i = 0; i < chars.Length; i++) { c = chars[i]; if ((c >= 0x0001) && (c <= 0x007F)) { buffer[count++] = (byte)c; } else if (c > 0x07FF) { buffer[count++] = (byte)(0xE0 | ((c >> 12) & 0x0F)); buffer[count++] = (byte)(0x80 | ((c >> 6) & 0x3F)); buffer[count++] = (byte)(0x80 | ((c >> 0) & 0x3F)); } else { buffer[count++] = (byte)(0xC0 | ((c >> 6) & 0x1F)); buffer[count++] = (byte)(0x80 | ((c >> 0) & 0x3F)); } } } }
Endian helper:
public class EndianSupport { public static char SwitchEndian(char x) { return (char)( (((char)((byte)(x))) << 8) | (((char)((byte)(x >> 8)))) ); } public static short SwitchEndian(short x) { return (short)( (((ushort)((byte)(x))) << 8) | (((ushort)((byte)(x >> 8)))) ); } public static int SwitchEndian(int x) { return (((int)((byte)(x))) << 24) | (((int)((byte)(x >> 8))) << 16) | (((int)((byte)(x >> 16))) << 8) | (((int)((byte)(x >> 24)))); } public static long SwitchEndian(long x) { return (((long)((byte)(x))) << 56) | (((long)((byte)(x >> 8))) << 48) | (((long)((byte)(x >> 16))) << 40) | (((long)((byte)(x >> 24))) << 32) | (((long)((byte)(x >> 32))) << 24) | (((long)((byte)(x >> 40))) << 16) | (((long)((byte)(x >> 48))) << 8) | (((long)((byte)(x >> 56)))); } public static ushort SwitchEndian(ushort x) { return (ushort)( (((ushort)((byte)(x))) << 8) | (((ushort)((byte)(x >> 8)))) ); } public static uint SwitchEndian(uint x) { return (((uint)((byte)(x))) << 24) | (((uint)((byte)(x >> 8))) << 16) | (((uint)((byte)(x >> 16))) << 8) | (((uint)((byte)(x >> 24)))); } public static ulong SwitchEndian(ulong x) { return (((ulong)((byte)(x))) << 56) | (((ulong)((byte)(x >> 8))) << 48) | (((ulong)((byte)(x >> 16))) << 40) | (((ulong)((byte)(x >> 24))) << 32) | (((ulong)((byte)(x >> 32))) << 24) | (((ulong)((byte)(x >> 40))) << 16) | (((ulong)((byte)(x >> 48))) << 8) | (((ulong)((byte)(x >> 56)))); } public static double SwitchEndian(double x) { MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(x); bw.Flush(); ms = new MemoryStream(SwitchEndian(ms.ToArray())); BinaryReader br = new BinaryReader(ms); return br.ReadDouble(); } public static float SwitchEndian(float x) { MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(x); bw.Flush(); ms = new MemoryStream(SwitchEndian(ms.ToArray())); BinaryReader br = new BinaryReader(ms); return br.ReadSingle(); } public static byte[] SwitchEndian(byte[] x) { byte[] rc = new byte[x.Length]; int j = x.Length - 1; for (int i = 0; i < x.Length; i++) { rc[i] = x[j]; j--; } return rc; } }
发表评论
-
JBoss Class Loader Ref
2009-10-15 22:35 991http://www.blogjava.net/agapple ... -
how to deploy SSH WEB App to JBoss5 AS
2009-10-15 18:51 15931.Create DataSource in WEB-INF/ ... -
How to deploy the Persistence unit in the global JNDI ?
2009-10-15 18:34 1237jboss recipe of the day By def ... -
integrate spring and jboss
2009-10-15 14:51 1252<component-scan> 无法在jboss ... -
SSH app deploy to JBoss5 AS
2009-10-13 18:46 16911. 部署时排除xml-apis-1.0.b2.jar, 这 ... -
ibatis3 Configuration
2009-08-25 14:36 30521.用maven 创建项目(俺 用netbeans). 2.在 ... -
调整线程池
2009-04-19 17:27 916所以假设为了使处理器得到充分使用,线程池应该有多大?如果知道系 ...
相关推荐
通过函数调用方式,实现了utf8与string的相互转换,可以非常方便的将string转换为utf8。
String to UTF-8String to UTF-8String to UTF-8String to UTF-8String to UTF-8
2、byte[]与string之间的转化 string str = 你好,hello; byte[] bytes; //byte[] 转换成 string bytes = Encoding.UTF8.GetBytes(str); //string 转换成 byte[] (字符串是用哪种编码生成的byte[]
delphi 开发的UTF8 ansistring转换动态库。 通过DELPHI与C++测试。 前面上传的资源未经过仔细验证,有问题,不好意思,重新修正上传
非常好用的UTF-8与string互转源代码,从实际项目中整理出来的源代码接口,直接使用即可。
C# string byte数组转换解析 C# string byte数组转换实现的过程是什么呢?C# string byte数组间的转换需要注意什么呢?C# string byte数组间转换所涉及的方法是什么呢?让我们来看看具体的内容: C# string byte数组...
ASCII 及UTF-8 与字符互相转换
utf-8、ANSI、Unicode相互转化c++实现 std::string ConverANSI2UTF8(const std::string & str); std::wstring ConverANSI2Unicode(const std::string str); std::wstring ConverUTF82Unicode(const std::string str)...
UTF8与string类型中的相互转换 delphi7源码
linux C/c++ 源代码,将中文字串与UTF-8格式字串相互转化,我在项目中使用的代码,完全可用
解决Invalid byte 1 of 1-byte UTF-8 sequence
utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体相互转换utf8 简体,繁体...
文件编码转换(utf8与gbk相互转换) 可以将utf8(gbk)的文件转换成gbk(utf8)格式
内容为utf8编码和unicode编码相互转换的C代码,关于utf8和unicode的用途另一篇博客有介绍,请参考。 压缩包 : ntf_code.rar 列表 ntf_code\uni_utf8.h ntf_code\utf8_u.c ntf_code\utf82u.c ntf_code\u2utf8.c ntf_...
CString转UTF8,UTF8转CString。
String转utf-8,http链接转utf-8
GBK、UTF-8批量文件3秒快速转码工具(支持GBK,UTF-8免费转换),UTF-8/GBK编码在线转换工具,压缩包可以有多目录与文件,如目录中有图片不会转码,但是会随转码好的文件一起打包下载。 使用帮助 . 上传压缩包(仅支持zip...
xe10_utf_8转换
文件的编码格式需要转换,gb2312,utf,utf-8等编码格式的相互转换等
C++Builder String,UNICODE,UTF8,ANSI互转的类,类的互相转换