author | aph |
Thu, 05 Feb 2015 11:47:33 -0800 | |
changeset 29190 | 9917b8aed927 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2004, 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 |
||
28 |
import java.nio.charset.Charset; |
|
29 |
import java.nio.charset.CharsetDecoder; |
|
30 |
import java.nio.charset.CharsetEncoder; |
|
31 |
import sun.nio.cs.HistoricallyNamedCharset; |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
32 |
import java.util.Arrays; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
33 |
import static sun.nio.cs.CharsetMapping.*; |
2 | 34 |
|
35 |
public class Big5_Solaris extends Charset implements HistoricallyNamedCharset |
|
36 |
{ |
|
37 |
public Big5_Solaris() { |
|
38 |
super("x-Big5-Solaris", ExtendedCharsets.aliasesFor("x-Big5-Solaris")); |
|
39 |
} |
|
40 |
||
41 |
public String historicalName() { |
|
42 |
return "Big5_Solaris"; |
|
43 |
} |
|
44 |
||
45 |
public boolean contains(Charset cs) { |
|
46 |
return ((cs.name().equals("US-ASCII")) |
|
47 |
|| (cs instanceof Big5) |
|
48 |
|| (cs instanceof Big5_Solaris)); |
|
49 |
} |
|
50 |
||
51 |
public CharsetDecoder newDecoder() { |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
52 |
initb2c(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
53 |
return new DoubleByte.Decoder(this, b2c, b2cSB, 0x40, 0xfe); |
2 | 54 |
} |
55 |
||
56 |
public CharsetEncoder newEncoder() { |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
57 |
initc2b(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
58 |
return new DoubleByte.Encoder(this, c2b, c2bIndex); |
2 | 59 |
} |
60 |
||
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
61 |
static char[][] b2c; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
62 |
static char[] b2cSB; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
63 |
private static volatile boolean b2cInitialized = false; |
2 | 64 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
65 |
static void initb2c() { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
66 |
if (b2cInitialized) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
67 |
return; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
68 |
synchronized (Big5_Solaris.class) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
69 |
if (b2cInitialized) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
70 |
return; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
71 |
Big5.initb2c(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
72 |
b2c = Big5.b2c.clone(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
73 |
// Big5 Solaris implementation has 7 additional mappings |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
74 |
int[] sol = new int[] { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
75 |
0xF9D6, 0x7881, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
76 |
0xF9D7, 0x92B9, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
77 |
0xF9D8, 0x88CF, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
78 |
0xF9D9, 0x58BB, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
79 |
0xF9DA, 0x6052, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
80 |
0xF9DB, 0x7CA7, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
81 |
0xF9DC, 0x5AFA }; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
82 |
if (b2c[0xf9] == DoubleByte.B2C_UNMAPPABLE) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
83 |
b2c[0xf9] = new char[0xfe - 0x40 + 1]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
84 |
Arrays.fill(b2c[0xf9], UNMAPPABLE_DECODING); |
2 | 85 |
} |
86 |
||
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
87 |
for (int i = 0; i < sol.length;) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
88 |
b2c[0xf9][sol[i++] & 0xff - 0x40] = (char)sol[i++]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
89 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
90 |
b2cSB = Big5.b2cSB; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
91 |
b2cInitialized = true; |
2 | 92 |
} |
93 |
} |
|
94 |
||
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
95 |
static char[] c2b; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
96 |
static char[] c2bIndex; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
97 |
private static volatile boolean c2bInitialized = false; |
2 | 98 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
99 |
static void initc2b() { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
100 |
if (c2bInitialized) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
101 |
return; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
102 |
synchronized (Big5_Solaris.class) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
103 |
if (c2bInitialized) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
104 |
return; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
105 |
Big5.initc2b(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
106 |
c2b = Big5.c2b.clone(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
107 |
c2bIndex = Big5.c2bIndex.clone(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
108 |
int[] sol = new int[] { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
109 |
0x7881, 0xF9D6, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
110 |
0x92B9, 0xF9D7, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
111 |
0x88CF, 0xF9D8, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
112 |
0x58BB, 0xF9D9, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
113 |
0x6052, 0xF9DA, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
114 |
0x7CA7, 0xF9DB, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
115 |
0x5AFA, 0xF9DC }; |
2 | 116 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
117 |
for (int i = 0; i < sol.length;) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
118 |
int c = sol[i++]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
119 |
// no need to check c2bIndex[c >>8], we know it points |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
120 |
// to the appropriate place. |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
121 |
c2b[c2bIndex[c >> 8] + (c & 0xff)] = (char)sol[i++]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
122 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
2
diff
changeset
|
123 |
c2bInitialized = true; |
2 | 124 |
} |
125 |
} |
|
126 |
} |