java.nio.charset.Charset.forName("utf8").decode http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html#decode%28java.nio.ByteBuffer%29解码字节序列
ED A0 80 ED B0 80
进入 Unicode 代码点:
U+10000
java.nio.charset.Charset.forName("utf8").decode http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html#decode%28java.nio.ByteBuffer%29还解码字节序列
F0 90 80 80
进入 Unicode 代码点:
U+10000
这一点已得到验证下面的代码 https://stackoverflow.com/q/8843742/632951/#snippet1.
现在这似乎告诉我UTF-8编码方案将解码ED A0 80 ED B0 80
and F0 90 80 80
到相同的 unicode 代码点。
但是,如果我访问https://www.google.com/search?query=%ED%A0%80%ED%B0%80 https://www.google.com/search?query=%ED%A0%80%ED%B0%80,
可以看到和页面明显不一样https://www.google.com/search?query=%F0%90%80%80 https://www.google.com/search?query=%F0%90%80%80
由于 Google 搜索也使用 UTF-8 编码方案(如果我错了,请纠正我),
这表明 UTF-8 无法解码ED A0 80 ED B0 80
and F0 90 80 80
到相同的 unicode 代码点。
所以基本上我想知道official标准,应该UTF-8解码ED A0 80 ED B0 80
字节序列转换为 Unicode 代码点 U+10000 ?
Code:
public class Test {
public static void main(String args[]) {
java.nio.ByteBuffer bb = java.nio.ByteBuffer.wrap(new byte[] { (byte) 0xED, (byte) 0xA0, (byte) 0x80, (byte) 0xED, (byte) 0xB0, (byte) 0x80 });
java.nio.CharBuffer cb = java.nio.charset.Charset.forName("utf8").decode(bb);
for (int x = 0, xx = cb.limit(); x < xx; ++x) {
System.out.println(Integer.toHexString(cb.get(x)));
}
System.out.println();
bb = java.nio.ByteBuffer.wrap(new byte[] { (byte) 0xF0, (byte) 0x90, (byte) 0x80, (byte) 0x80 });
cb = java.nio.charset.Charset.forName("utf8").decode(bb);
for (int x = 0, xx = cb.limit(); x < xx; ++x) {
System.out.println(Integer.toHexString(cb.get(x)));
}
}
}