jdk/src/share/classes/sun/nio/cs/ext/MS932_0213.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3052 5c9886498f31
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3052
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
     4
 *
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3052
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3052
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    10
 *
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    15
 * accompanied this code).
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    16
 *
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3052
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3052
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3052
diff changeset
    23
 * questions.
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    24
 */
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    25
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    26
package sun.nio.cs.ext;
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    27
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    28
import java.nio.charset.Charset;
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    29
import java.nio.charset.CharsetEncoder;
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    30
import java.nio.charset.CharsetDecoder;
3052
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    31
import static sun.nio.cs.CharsetMapping.*;
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    32
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    33
public class MS932_0213 extends Charset {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    34
    public MS932_0213() {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    35
        super("x-MS932_0213", ExtendedCharsets.aliasesFor("MS932_0213"));
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    36
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    37
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    38
    public boolean contains(Charset cs) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    39
        return ((cs.name().equals("US-ASCII"))
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    40
                || (cs instanceof MS932)
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    41
                || (cs instanceof MS932_0213));
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    42
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    43
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    44
    public CharsetDecoder newDecoder() {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    45
        return new Decoder(this);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    46
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    47
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    48
    public CharsetEncoder newEncoder() {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    49
        return new Encoder(this);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    50
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    51
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    52
    protected static class Decoder extends SJIS_0213.Decoder {
3052
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    53
        static DoubleByte.Decoder decMS932 =
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    54
            (DoubleByte.Decoder)new MS932().newDecoder();
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    55
        protected Decoder(Charset cs) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    56
            super(cs);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    57
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    58
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    59
        protected char decodeDouble(int b1, int b2) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    60
            char c = decMS932.decodeDouble(b1, b2);
3052
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    61
            if (c == UNMAPPABLE_DECODING)
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    62
                return super.decodeDouble(b1, b2);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    63
            return c;
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    64
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    65
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    66
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    67
    protected static class Encoder extends SJIS_0213.Encoder {
3052
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    68
        // we only use its encodeChar() method
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    69
        static DoubleByte.Encoder encMS932 =
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    70
            (DoubleByte.Encoder)new MS932().newEncoder();
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    71
        protected Encoder(Charset cs) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    72
            super(cs);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    73
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    74
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    75
        protected int encodeChar(char ch) {
3052
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    76
            int db = encMS932.encodeChar(ch);
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    77
            if (db == UNMAPPABLE_ENCODING)
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    78
                return super.encodeChar(ch);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    79
            return db;
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    80
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    81
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    82
}