src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM834.java
author prappo
Wed, 08 Nov 2017 18:45:14 +0300
branchhttp-client-branch
changeset 55786 a32b59f7b7fb
parent 47216 71c04702a3d5
permissions -rw-r--r--
http-client-branch: merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13366
diff changeset
     3
 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * 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
     8
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    10
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2921
diff changeset
    24
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
package sun.nio.cs.ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.charset.CharsetDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.nio.charset.CoderResult;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 25859
diff changeset
    37
import sun.nio.cs.DoubleByte;
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    38
import static sun.nio.cs.CharsetMapping.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// EBCDIC DBCS-only Korean
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    41
public class IBM834 extends Charset
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public IBM834() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        super("x-IBM834", ExtendedCharsets.aliasesFor("x-IBM834"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public boolean contains(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        return (cs instanceof IBM834);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public CharsetDecoder newDecoder() {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    52
        IBM933.initb2c();
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    53
        return new DoubleByte.Decoder_DBCSONLY(
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    54
            this, IBM933.b2c, null, 0x40, 0xfe);  // hardcode the b2min/max
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public CharsetEncoder newEncoder() {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    58
        IBM933.initc2b();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return new Encoder(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    62
    protected static class Encoder extends DoubleByte.Encoder_DBCSONLY {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        public Encoder(Charset cs) {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    64
            super(cs, new byte[] {(byte)0xfe, (byte)0xfe},
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 28969
diff changeset
    65
                  IBM933.c2b, IBM933.c2bIndex, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    68
        public int encodeChar(char ch) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    69
            int bb = super.encodeChar(ch);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    70
            if (bb == UNMAPPABLE_ENCODING) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                // Cp834 has 6 additional non-roundtrip char->bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                // mappings, see#6379808
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                if (ch == '\u00b7') {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    74
                    return 0x4143;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                } else if (ch == '\u00ad') {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    76
                    return 0x4148;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                } else if (ch == '\u2015') {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    78
                    return 0x4149;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                } else if (ch == '\u223c') {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    80
                    return 0x42a1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                } else if (ch == '\uff5e') {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    82
                    return 0x4954;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                } else if (ch == '\u2299') {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    84
                    return 0x496f;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    87
            return bb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        public boolean isLegalReplacement(byte[] repl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            if (repl.length == 2 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                repl[0] == (byte)0xfe && repl[1] == (byte)0xfe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return super.isLegalReplacement(repl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}