author | martin |
Wed, 30 Jun 2010 16:11:32 -0700 | |
changeset 5986 | 04eb44085c00 |
parent 5785 | 5dfabe612d10 |
child 13257 | 5cf4ff2cbb37 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.nio.cs.ext; |
|
27 |
||
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
28 |
import java.nio.ByteBuffer; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
29 |
import java.nio.CharBuffer; |
2 | 30 |
import java.nio.charset.Charset; |
31 |
import java.nio.charset.CharsetDecoder; |
|
32 |
import java.nio.charset.CharsetEncoder; |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
33 |
import java.nio.charset.CoderResult; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
34 |
import java.util.Arrays; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
35 |
import sun.nio.cs.Surrogate; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
36 |
import static sun.nio.cs.CharsetMapping.*; |
2 | 37 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
38 |
public class HKSCS { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
39 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
40 |
public static class Decoder extends DoubleByte.Decoder { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
41 |
static int b2Min = 0x40; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
42 |
static int b2Max = 0xfe; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
43 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
44 |
private char[][] b2cBmp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
45 |
private char[][] b2cSupp; |
5785
5dfabe612d10
6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents:
5506
diff
changeset
|
46 |
private DoubleByte.Decoder big5Dec; |
2 | 47 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
48 |
protected Decoder(Charset cs, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
49 |
DoubleByte.Decoder big5Dec, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
50 |
char[][] b2cBmp, char[][] b2cSupp) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
51 |
{ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
52 |
// super(cs, 0.5f, 1.0f); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
53 |
// need to extends DoubleByte.Decoder so the |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
54 |
// sun.io can use it. this implementation |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
55 |
super(cs, 0.5f, 1.0f, null, null, 0, 0); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
56 |
this.big5Dec = big5Dec; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
57 |
this.b2cBmp = b2cBmp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
58 |
this.b2cSupp = b2cSupp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
59 |
} |
2 | 60 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
61 |
public char decodeSingle(int b) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
62 |
return big5Dec.decodeSingle(b); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
63 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
64 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
65 |
public char decodeBig5(int b1, int b2) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
66 |
return big5Dec.decodeDouble(b1, b2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
67 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
68 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
69 |
public char decodeDouble(int b1, int b2) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
70 |
return b2cBmp[b1][b2 - b2Min]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
71 |
} |
2 | 72 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
73 |
public char decodeDoubleEx(int b1, int b2) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
74 |
/* if the b2cSupp is null, the subclass need |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
75 |
to override the methold |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
76 |
if (b2cSupp == null) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
77 |
return UNMAPPABLE_DECODING; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
78 |
*/ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
79 |
return b2cSupp[b1][b2 - b2Min]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
80 |
} |
2 | 81 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
82 |
protected CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
83 |
byte[] sa = src.array(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
84 |
int sp = src.arrayOffset() + src.position(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
85 |
int sl = src.arrayOffset() + src.limit(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
86 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
87 |
char[] da = dst.array(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
88 |
int dp = dst.arrayOffset() + dst.position(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
89 |
int dl = dst.arrayOffset() + dst.limit(); |
2 | 90 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
91 |
try { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
92 |
while (sp < sl) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
93 |
int b1 = sa[sp] & 0xff; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
94 |
char c = decodeSingle(b1); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
95 |
int inSize = 1, outSize = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
96 |
char[] cc = null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
97 |
if (c == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
98 |
if (sl - sp < 2) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
99 |
return CoderResult.UNDERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
100 |
int b2 = sa[sp + 1] & 0xff; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
101 |
inSize++; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
102 |
if (b2 < b2Min || b2 > b2Max) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
103 |
return CoderResult.unmappableForLength(2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
104 |
c = decodeDouble(b1, b2); //bmp |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
105 |
if (c == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
106 |
c = decodeDoubleEx(b1, b2); //supp |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
107 |
if (c == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
108 |
c = decodeBig5(b1, b2); //big5 |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
109 |
if (c == UNMAPPABLE_DECODING) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
110 |
return CoderResult.unmappableForLength(2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
111 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
112 |
// supplementary character in u+2xxxx area |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
113 |
outSize = 2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
114 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
115 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
116 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
117 |
if (dl - dp < outSize) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
118 |
return CoderResult.OVERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
119 |
if (outSize == 2) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
120 |
// supplementary characters |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
121 |
da[dp++] = Surrogate.high(0x20000 + c); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
122 |
da[dp++] = Surrogate.low(0x20000 + c); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
123 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
124 |
da[dp++] = c; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
125 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
126 |
sp += inSize; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
127 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
128 |
return CoderResult.UNDERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
129 |
} finally { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
130 |
src.position(sp - src.arrayOffset()); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
131 |
dst.position(dp - dst.arrayOffset()); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
132 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
133 |
} |
2 | 134 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
135 |
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
136 |
int mark = src.position(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
137 |
try { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
138 |
while (src.hasRemaining()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
139 |
char[] cc = null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
140 |
int b1 = src.get() & 0xff; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
141 |
int inSize = 1, outSize = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
142 |
char c = decodeSingle(b1); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
143 |
if (c == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
144 |
if (src.remaining() < 1) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
145 |
return CoderResult.UNDERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
146 |
int b2 = src.get() & 0xff; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
147 |
inSize++; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
148 |
if (b2 < b2Min || b2 > b2Max) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
149 |
return CoderResult.unmappableForLength(2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
150 |
c = decodeDouble(b1, b2); //bmp |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
151 |
if (c == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
152 |
c = decodeDoubleEx(b1, b2); //supp |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
153 |
if (c == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
154 |
c = decodeBig5(b1, b2); //big5 |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
155 |
if (c == UNMAPPABLE_DECODING) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
156 |
return CoderResult.unmappableForLength(2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
157 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
158 |
outSize = 2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
159 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
160 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
161 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
162 |
if (dst.remaining() < outSize) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
163 |
return CoderResult.OVERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
164 |
if (outSize == 2) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
165 |
dst.put(Surrogate.high(0x20000 + c)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
166 |
dst.put(Surrogate.low(0x20000 + c)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
167 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
168 |
dst.put(c); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
169 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
170 |
mark += inSize; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
171 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
172 |
return CoderResult.UNDERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
173 |
} finally { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
174 |
src.position(mark); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
175 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
176 |
} |
2 | 177 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
178 |
public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
179 |
if (src.hasArray() && dst.hasArray()) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
180 |
return decodeArrayLoop(src, dst); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
181 |
else |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
182 |
return decodeBufferLoop(src, dst); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
183 |
} |
2 | 184 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
185 |
static void initb2c(char[][]b2c, String[] b2cStr) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
186 |
{ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
187 |
for (int i = 0; i < b2cStr.length; i++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
188 |
if (b2cStr[i] == null) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
189 |
b2c[i] = DoubleByte.B2C_UNMAPPABLE; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
190 |
else |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
191 |
b2c[i] = b2cStr[i].toCharArray(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
192 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
193 |
} |
2 | 194 |
|
195 |
} |
|
196 |
||
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
197 |
public static class Encoder extends DoubleByte.Encoder { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
198 |
private DoubleByte.Encoder big5Enc; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
199 |
private char[][] c2bBmp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
200 |
private char[][] c2bSupp; |
2 | 201 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
202 |
protected Encoder(Charset cs, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
203 |
DoubleByte.Encoder big5Enc, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
204 |
char[][] c2bBmp, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
205 |
char[][] c2bSupp) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
206 |
{ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
207 |
super(cs, null, null); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
208 |
this.big5Enc = big5Enc; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
209 |
this.c2bBmp = c2bBmp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
210 |
this.c2bSupp = c2bSupp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
211 |
} |
2 | 212 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
213 |
public int encodeBig5(char ch) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
214 |
return big5Enc.encodeChar(ch); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
215 |
} |
2 | 216 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
217 |
public int encodeChar(char ch) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
218 |
int bb = c2bBmp[ch >> 8][ch & 0xff]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
219 |
if (bb == UNMAPPABLE_ENCODING) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
220 |
return encodeBig5(ch); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
221 |
return bb; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
222 |
} |
2 | 223 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
224 |
public int encodeSupp(int cp) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
225 |
if ((cp & 0xf0000) != 0x20000) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
226 |
return UNMAPPABLE_ENCODING; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
227 |
return c2bSupp[(cp >> 8) & 0xff][cp & 0xff]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
228 |
} |
2 | 229 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
230 |
public boolean canEncode(char c) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
231 |
return encodeChar(c) != UNMAPPABLE_ENCODING; |
2 | 232 |
} |
233 |
||
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
234 |
protected CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
235 |
char[] sa = src.array(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
236 |
int sp = src.arrayOffset() + src.position(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
237 |
int sl = src.arrayOffset() + src.limit(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
238 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
239 |
byte[] da = dst.array(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
240 |
int dp = dst.arrayOffset() + dst.position(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
241 |
int dl = dst.arrayOffset() + dst.limit(); |
2 | 242 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
243 |
try { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
244 |
while (sp < sl) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
245 |
char c = sa[sp]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
246 |
int inSize = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
247 |
int bb = encodeChar(c); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
248 |
if (bb == UNMAPPABLE_ENCODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
249 |
if (Character.isSurrogate(c)) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
250 |
int cp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
251 |
if ((cp = sgp().parse(c, sa, sp, sl)) < 0) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
252 |
return sgp.error(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
253 |
bb = encodeSupp(cp); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
254 |
if (bb == UNMAPPABLE_ENCODING) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
255 |
return CoderResult.unmappableForLength(2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
256 |
inSize = 2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
257 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
258 |
return CoderResult.unmappableForLength(1); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
259 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
260 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
261 |
if (bb > MAX_SINGLEBYTE) { // DoubleByte |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
262 |
if (dl - dp < 2) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
263 |
return CoderResult.OVERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
264 |
da[dp++] = (byte)(bb >> 8); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
265 |
da[dp++] = (byte)bb; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
266 |
} else { // SingleByte |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
267 |
if (dl - dp < 1) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
268 |
return CoderResult.OVERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
269 |
da[dp++] = (byte)bb; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
270 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
271 |
sp += inSize; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
272 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
273 |
return CoderResult.UNDERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
274 |
} finally { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
275 |
src.position(sp - src.arrayOffset()); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
276 |
dst.position(dp - dst.arrayOffset()); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
277 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
278 |
} |
2 | 279 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
280 |
protected CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
281 |
int mark = src.position(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
282 |
try { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
283 |
while (src.hasRemaining()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
284 |
int inSize = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
285 |
char c = src.get(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
286 |
int bb = encodeChar(c); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
287 |
if (bb == UNMAPPABLE_ENCODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
288 |
if (Character.isSurrogate(c)) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
289 |
int cp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
290 |
if ((cp = sgp().parse(c, src)) < 0) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
291 |
return sgp.error(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
292 |
bb = encodeSupp(cp); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
293 |
if (bb == UNMAPPABLE_ENCODING) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
294 |
return CoderResult.unmappableForLength(2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
295 |
inSize = 2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
296 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
297 |
return CoderResult.unmappableForLength(1); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
298 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
299 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
300 |
if (bb > MAX_SINGLEBYTE) { // DoubleByte |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
301 |
if (dst.remaining() < 2) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
302 |
return CoderResult.OVERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
303 |
dst.put((byte)(bb >> 8)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
304 |
dst.put((byte)(bb)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
305 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
306 |
if (dst.remaining() < 1) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
307 |
return CoderResult.OVERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
308 |
dst.put((byte)bb); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
309 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
310 |
mark += inSize; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
311 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
312 |
return CoderResult.UNDERFLOW; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
313 |
} finally { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
314 |
src.position(mark); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
315 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
316 |
} |
2 | 317 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
318 |
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
319 |
if (src.hasArray() && dst.hasArray()) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
320 |
return encodeArrayLoop(src, dst); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
321 |
else |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
322 |
return encodeBufferLoop(src, dst); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
323 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
324 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
325 |
static char[] C2B_UNMAPPABLE = new char[0x100]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
326 |
static { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
327 |
Arrays.fill(C2B_UNMAPPABLE, (char)UNMAPPABLE_ENCODING); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
328 |
} |
2 | 329 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
330 |
static void initc2b(char[][] c2b, String[] b2cStr, String pua) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
331 |
// init c2b/c2bSupp from b2cStr and supp |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
332 |
int b2Min = 0x40; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
333 |
Arrays.fill(c2b, C2B_UNMAPPABLE); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
334 |
for (int b1 = 0; b1 < 0x100; b1++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
335 |
String s = b2cStr[b1]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
336 |
if (s == null) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
337 |
continue; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
338 |
for (int i = 0; i < s.length(); i++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
339 |
char c = s.charAt(i); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
340 |
int hi = c >> 8; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
341 |
if (c2b[hi] == C2B_UNMAPPABLE) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
342 |
c2b[hi] = new char[0x100]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
343 |
Arrays.fill(c2b[hi], (char)UNMAPPABLE_ENCODING); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
344 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
345 |
c2b[hi][c & 0xff] = (char)((b1 << 8) | (i + b2Min)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
346 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
347 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
348 |
if (pua != null) { // add the compatibility pua entries |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
349 |
char c = '\ue000'; //first pua character |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
350 |
for (int i = 0; i < pua.length(); i++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
351 |
char bb = pua.charAt(i); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
352 |
if (bb != UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
353 |
int hi = c >> 8; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
354 |
if (c2b[hi] == C2B_UNMAPPABLE) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
355 |
c2b[hi] = new char[0x100]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
356 |
Arrays.fill(c2b[hi], (char)UNMAPPABLE_ENCODING); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
357 |
} |
5785
5dfabe612d10
6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents:
5506
diff
changeset
|
358 |
c2b[hi][c & 0xff] = bb; |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
359 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
360 |
c++; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
361 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
362 |
} |
2 | 363 |
} |
364 |
} |
|
365 |
} |