src/jdk.charsets/share/classes/sun/nio/cs/ext/MS932_0213.java
author weijun
Thu, 24 Oct 2019 15:53:20 +0800
changeset 58776 ea153023d832
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231598: keytool does not export sun.security.mscapi Reviewed-by: mullan
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;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 25859
diff changeset
    31
import sun.nio.cs.DoubleByte;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 25859
diff changeset
    32
import sun.nio.cs.*;
3052
5c9886498f31 6299219: euro sign failed to be printed in Console on Localized Windows platform with GBK encoding
sherman
parents: 400
diff changeset
    33
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
    34
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    35
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
    36
    public MS932_0213() {
47025
e78bddc74bf5 8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents: 28969
diff changeset
    37
        super("x-MS932_0213", ExtendedCharsets.aliasesFor("x-MS932_0213"));
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    38
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    39
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    40
    public boolean contains(Charset cs) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    41
        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
    42
                || (cs instanceof MS932)
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    43
                || (cs instanceof MS932_0213));
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    44
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    45
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    46
    public CharsetDecoder newDecoder() {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    47
        return new Decoder(this);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    48
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    49
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    50
    public CharsetEncoder newEncoder() {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    51
        return new Encoder(this);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    52
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    53
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    54
    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
    55
        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
    56
            (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
    57
        protected Decoder(Charset cs) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    58
            super(cs);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    59
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    60
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    61
        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
    62
            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
    63
            if (c == UNMAPPABLE_DECODING)
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    64
                return super.decodeDouble(b1, b2);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    65
            return c;
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
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    68
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    69
    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
    70
        // 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
    71
        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
    72
            (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
    73
        protected Encoder(Charset cs) {
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    74
            super(cs);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    75
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    76
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    77
        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
    78
            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
    79
            if (db == UNMAPPABLE_ENCODING)
400
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    80
                return super.encodeChar(ch);
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    81
            return db;
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    82
        }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    83
    }
9f3afee24320 6529796: Support JIS X 0213:2004 in existing JDK versions, especially for Windows Vista
sherman
parents:
diff changeset
    84
}