test/jdk/sun/nio/cs/OLD/IBM943C_OLD.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200 (2017-09-12)
changeset 47216 71c04702a3d5
parent 5506 jdk/test/sun/nio/cs/OLD/IBM943C_OLD.java@202f599c92aa
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
     4
 *
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
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: 2921
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    10
 *
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    15
 * accompanied this code).
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    16
 *
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    23
 * questions.
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    24
 */
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    25
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    26
/*
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    27
 */
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    28
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    29
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    30
import java.nio.charset.Charset;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    31
import java.nio.charset.CharsetDecoder;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    32
import java.nio.charset.CharsetEncoder;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    33
import java.nio.charset.CharacterCodingException;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    34
import sun.nio.cs.HistoricallyNamedCharset;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    35
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    36
public class IBM943C_OLD extends Charset implements HistoricallyNamedCharset
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    37
{
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    38
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    39
    public IBM943C_OLD() {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    40
        super("x-IBM943C_OLD", null);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    41
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    42
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    43
    public String historicalName() {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    44
        return "Cp943_OLDC";
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    45
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    46
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    47
    public boolean contains(Charset cs) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    48
        return ((cs.name().equals("US-ASCII"))
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    49
                || (cs instanceof IBM943C_OLD));
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    50
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    51
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    52
    public CharsetDecoder newDecoder() {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    53
        return new Decoder(this);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    54
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    55
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    56
    public CharsetEncoder newEncoder() {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    57
        return new Encoder(this);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    58
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    59
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    60
    private static class Decoder extends IBM943_OLD.Decoder {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    61
        protected static final String singleByteToChar;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    62
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    63
        static {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    64
          String indexs = "";
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    65
          for (char c = '\0'; c < '\u0080'; ++c) indexs += c;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    66
              singleByteToChar = indexs +
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    67
                                 IBM943_OLD.Decoder.singleByteToChar.substring(indexs.length());
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    68
        }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    69
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    70
        public Decoder(Charset cs) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    71
            super(cs, singleByteToChar);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    72
        }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    73
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    74
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    75
    private static class Encoder extends IBM943_OLD.Encoder {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    76
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    77
        protected static final short index1[];
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    78
        protected static final String index2a;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    79
        protected static final int shift = 6;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    80
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    81
        static {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    82
            String indexs = "";
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    83
            for (char c = '\0'; c < '\u0080'; ++c) indexs += c;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    84
                index2a = IBM943_OLD.Encoder.index2a + indexs;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    85
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    86
            int o = IBM943_OLD.Encoder.index2a.length() + 15000;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    87
            index1 = new short[IBM943_OLD.Encoder.index1.length];
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    88
            System.arraycopy(IBM943_OLD.Encoder.index1,
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    89
                             0,
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    90
                             index1,
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    91
                             0,
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    92
                             IBM943_OLD.Encoder.index1.length);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    93
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    94
            for (int i = 0; i * (1<<shift) < 128; ++i) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    95
                index1[i] = (short)(o + i * (1<<shift));
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    96
            }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    97
        }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    98
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
    99
        public Encoder(Charset cs) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
   100
            super(cs, index1, index2a);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
   101
        }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
   102
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents:
diff changeset
   103
}