2
|
1 |
|
|
2 |
/*
|
5506
|
3 |
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
5 |
*
|
|
6 |
* This code is free software; you can redistribute it and/or modify it
|
|
7 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
8 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
9 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
10 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
11 |
*
|
|
12 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
16 |
* accompanied this code).
|
|
17 |
*
|
|
18 |
* You should have received a copy of the GNU General Public License version
|
|
19 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
20 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
21 |
*
|
5506
|
22 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
23 |
* or visit www.oracle.com if you need additional information or have any
|
|
24 |
* questions.
|
2
|
25 |
*/
|
|
26 |
|
|
27 |
/*
|
|
28 |
*/
|
|
29 |
|
|
30 |
package sun.nio.cs.ext;
|
|
31 |
|
|
32 |
import java.nio.ByteBuffer;
|
|
33 |
import java.nio.charset.Charset;
|
|
34 |
import java.nio.charset.CharsetDecoder;
|
|
35 |
import java.nio.charset.CharsetEncoder;
|
|
36 |
import java.nio.charset.CoderResult;
|
2921
|
37 |
import static sun.nio.cs.CharsetMapping.*;
|
2
|
38 |
|
|
39 |
// EBCDIC DBCS-only Korean
|
2921
|
40 |
public class IBM834 extends Charset
|
2
|
41 |
{
|
|
42 |
public IBM834() {
|
|
43 |
super("x-IBM834", ExtendedCharsets.aliasesFor("x-IBM834"));
|
|
44 |
}
|
|
45 |
|
|
46 |
public boolean contains(Charset cs) {
|
|
47 |
return (cs instanceof IBM834);
|
|
48 |
}
|
|
49 |
|
|
50 |
public CharsetDecoder newDecoder() {
|
2921
|
51 |
IBM933.initb2c();
|
|
52 |
return new DoubleByte.Decoder_EBCDIC_DBCSONLY(
|
|
53 |
this, IBM933.b2c, 0x40, 0xfe); // hardcode the b2min/max
|
2
|
54 |
}
|
|
55 |
|
|
56 |
public CharsetEncoder newEncoder() {
|
2921
|
57 |
IBM933.initc2b();
|
2
|
58 |
return new Encoder(this);
|
|
59 |
}
|
|
60 |
|
2921
|
61 |
protected static class Encoder extends DoubleByte.Encoder_EBCDIC_DBCSONLY {
|
2
|
62 |
public Encoder(Charset cs) {
|
2921
|
63 |
super(cs, new byte[] {(byte)0xfe, (byte)0xfe},
|
|
64 |
IBM933.c2b, IBM933.c2bIndex);
|
2
|
65 |
}
|
|
66 |
|
2921
|
67 |
public int encodeChar(char ch) {
|
|
68 |
int bb = super.encodeChar(ch);
|
|
69 |
if (bb == UNMAPPABLE_ENCODING) {
|
2
|
70 |
// Cp834 has 6 additional non-roundtrip char->bytes
|
|
71 |
// mappings, see#6379808
|
|
72 |
if (ch == '\u00b7') {
|
2921
|
73 |
return 0x4143;
|
2
|
74 |
} else if (ch == '\u00ad') {
|
2921
|
75 |
return 0x4148;
|
2
|
76 |
} else if (ch == '\u2015') {
|
2921
|
77 |
return 0x4149;
|
2
|
78 |
} else if (ch == '\u223c') {
|
2921
|
79 |
return 0x42a1;
|
2
|
80 |
} else if (ch == '\uff5e') {
|
2921
|
81 |
return 0x4954;
|
2
|
82 |
} else if (ch == '\u2299') {
|
2921
|
83 |
return 0x496f;
|
2
|
84 |
}
|
|
85 |
}
|
2921
|
86 |
return bb;
|
2
|
87 |
}
|
|
88 |
|
|
89 |
public boolean isLegalReplacement(byte[] repl) {
|
|
90 |
if (repl.length == 2 &&
|
|
91 |
repl[0] == (byte)0xfe && repl[1] == (byte)0xfe)
|
|
92 |
return true;
|
|
93 |
return super.isLegalReplacement(repl);
|
|
94 |
}
|
|
95 |
|
|
96 |
}
|
|
97 |
}
|