author | sherman |
Tue, 24 Jul 2012 12:17:39 -0700 | |
changeset 13366 | 2f5fdf6d8c22 |
parent 7668 | d4a77089c587 |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2003, 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.ByteBuffer; |
|
29 |
import java.nio.CharBuffer; |
|
30 |
import java.nio.charset.Charset; |
|
31 |
import java.nio.charset.CharsetDecoder; |
|
32 |
import java.nio.charset.CharsetEncoder; |
|
33 |
import java.nio.charset.CoderResult; |
|
34 |
import sun.nio.cs.HistoricallyNamedCharset; |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
35 |
import static sun.nio.cs.CharsetMapping.*; |
2 | 36 |
|
37 |
public class EUC_JP_Open |
|
38 |
extends Charset |
|
39 |
implements HistoricallyNamedCharset |
|
40 |
{ |
|
41 |
public EUC_JP_Open() { |
|
42 |
super("x-eucJP-Open", ExtendedCharsets.aliasesFor("x-eucJP-Open")); |
|
43 |
} |
|
44 |
||
45 |
public String historicalName() { |
|
46 |
return "EUC_JP_Solaris"; |
|
47 |
} |
|
48 |
||
49 |
public boolean contains(Charset cs) { |
|
50 |
return ((cs.name().equals("US-ASCII")) |
|
51 |
|| (cs instanceof JIS_X_0201) |
|
52 |
|| (cs instanceof EUC_JP)); |
|
53 |
} |
|
54 |
||
55 |
public CharsetDecoder newDecoder() { |
|
56 |
return new Decoder(this); |
|
57 |
} |
|
58 |
||
59 |
public CharsetEncoder newEncoder() { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
60 |
return new Encoder(this); |
2 | 61 |
} |
62 |
||
63 |
private static class Decoder extends EUC_JP.Decoder { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
64 |
private static DoubleByte.Decoder DEC0208_Solaris = |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
65 |
(DoubleByte.Decoder)new JIS_X_0208_Solaris().newDecoder(); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
66 |
private static DoubleByte.Decoder DEC0212_Solaris = |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
67 |
(DoubleByte.Decoder)new JIS_X_0212_Solaris().newDecoder(); |
2 | 68 |
|
69 |
private Decoder(Charset cs) { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
70 |
// JIS_X_0208_Solaris only has the "extra" mappings, it |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
71 |
// does not have the JIS_X_0208 entries |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
72 |
super(cs, 0.5f, 1.0f, DEC0201, DEC0208, DEC0212_Solaris); |
2 | 73 |
} |
74 |
||
75 |
protected char decodeDouble(int byte1, int byte2) { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
76 |
char c = super.decodeDouble(byte1, byte2); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
77 |
if (c == UNMAPPABLE_DECODING) |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
78 |
return DEC0208_Solaris.decodeDouble(byte1 - 0x80, byte2 - 0x80); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
79 |
return c; |
2 | 80 |
} |
81 |
} |
|
82 |
||
83 |
private static class Encoder extends EUC_JP.Encoder { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
84 |
private static DoubleByte.Encoder ENC0208_Solaris = |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
85 |
(DoubleByte.Encoder)new JIS_X_0208_Solaris().newEncoder(); |
2 | 86 |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
87 |
private static DoubleByte.Encoder ENC0212_Solaris = |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
88 |
(DoubleByte.Encoder)new JIS_X_0212_Solaris().newEncoder(); |
2 | 89 |
|
90 |
private Encoder(Charset cs) { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
91 |
// The EUC_JP_Open has some interesting tweak for the |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
92 |
// encoding, so can't just pass the euc0208_solaris to |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
93 |
// the euc_jp. Have to override the encodeDouble() as |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
94 |
// showed below (mapping testing catches this). |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
95 |
// super(cs, 3.0f, 3.0f, ENC0201, ENC0208_Solaris, ENC0212_Solaris); |
2 | 96 |
super(cs); |
97 |
} |
|
98 |
||
99 |
protected int encodeDouble(char ch) { |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
100 |
int b = super.encodeDouble(ch); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
101 |
if (b != UNMAPPABLE_ENCODING) |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
102 |
return b; |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
103 |
b = ENC0208_Solaris.encodeChar(ch); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
104 |
if (b != UNMAPPABLE_ENCODING && b > 0x7500) { |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
105 |
return 0x8F8080 + ENC0212_Solaris.encodeChar(ch); |
2 | 106 |
} |
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
107 |
return b == UNMAPPABLE_ENCODING ? b : b + 0x8080; |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
108 |
|
2 | 109 |
} |
110 |
} |
|
111 |
} |