jdk/src/share/classes/sun/nio/cs/ext/EUC_JP_Open.java
author sherman
Tue, 24 Jul 2012 12:17:39 -0700
changeset 13366 2f5fdf6d8c22
parent 7668 d4a77089c587
child 14342 8435a30053c1
permissions -rw-r--r--
6653797: Reimplement JDK charset repository charsets.jar Summary: Migrated all jis based charsets to new implementation Reviewed-by: okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5785
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
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: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.cs.ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.charset.CharsetDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.CoderResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class EUC_JP_Open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    extends Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    implements HistoricallyNamedCharset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public EUC_JP_Open() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        super("x-eucJP-Open", ExtendedCharsets.aliasesFor("x-eucJP-Open"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public String historicalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        return "EUC_JP_Solaris";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public boolean contains(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        return ((cs.name().equals("US-ASCII"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                || (cs instanceof JIS_X_0201)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                || (cs instanceof EUC_JP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public CharsetDecoder newDecoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return new Decoder(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public CharsetEncoder newEncoder() {
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 7668
diff changeset
    60
        return new Encoder(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            super(cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}