2
|
1 |
/*
|
|
2 |
* Copyright 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
|
|
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
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
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 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.io;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* The SJIS converters follow the Shift JIS definition in the JIS
|
|
30 |
* X0208:1997 standard as much as possible. The MS932 converters must
|
|
31 |
* be used where the Microsoft Code Page 932 character repertoire and
|
|
32 |
* Unicode mappings are required.
|
|
33 |
*
|
|
34 |
* @author Limin Shi
|
|
35 |
* @author Mark Son-Bell
|
|
36 |
*/
|
|
37 |
|
|
38 |
public class ByteToCharSJIS extends ByteToCharJIS0208 {
|
|
39 |
ByteToCharJIS0201 bcJIS0201 = new ByteToCharJIS0201();
|
|
40 |
|
|
41 |
public String getCharacterEncoding() {
|
|
42 |
return "SJIS";
|
|
43 |
}
|
|
44 |
|
|
45 |
protected char convSingleByte(int b) {
|
|
46 |
// If the high bits are all off, it's ASCII == Unicode
|
|
47 |
if ((b & 0xFF80) == 0) {
|
|
48 |
return (char)b;
|
|
49 |
}
|
|
50 |
return bcJIS0201.getUnicode(b);
|
|
51 |
}
|
|
52 |
|
|
53 |
protected char getUnicode(int c1, int c2) {
|
|
54 |
int adjust = c2 < 0x9F ? 1 : 0;
|
|
55 |
int rowOffset = c1 < 0xA0 ? 0x70 : 0xB0;
|
|
56 |
int cellOffset = (adjust == 1) ? (c2 > 0x7F ? 0x20 : 0x1F) : 0x7E;
|
|
57 |
int b1 = ((c1 - rowOffset) << 1) - adjust;
|
|
58 |
int b2 = c2 - cellOffset;
|
|
59 |
return super.getUnicode(b1, b2);
|
|
60 |
}
|
|
61 |
|
|
62 |
String prt(int i) {
|
|
63 |
return Integer.toString(i,16);
|
|
64 |
}
|
|
65 |
}
|