Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/nio/cs/ext/IBM834.java
38919 views
1/*2* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation. Oracle designates this8* particular file as subject to the "Classpath" exception as provided9* by Oracle in the LICENSE file that accompanied this code.10*11* This code is distributed in the hope that it will be useful, but WITHOUT12* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or13* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License14* version 2 for more details (a copy is included in the LICENSE file that15* accompanied this code).16*17* You should have received a copy of the GNU General Public License version18* 2 along with this work; if not, write to the Free Software Foundation,19* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.20*21* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA22* or visit www.oracle.com if you need additional information or have any23* questions.24*/2526/*27*/2829package sun.nio.cs.ext;3031import java.nio.ByteBuffer;32import java.nio.charset.Charset;33import java.nio.charset.CharsetDecoder;34import java.nio.charset.CharsetEncoder;35import java.nio.charset.CoderResult;36import static sun.nio.cs.CharsetMapping.*;3738// EBCDIC DBCS-only Korean39public class IBM834 extends Charset40{41public IBM834() {42super("x-IBM834", ExtendedCharsets.aliasesFor("x-IBM834"));43}4445public boolean contains(Charset cs) {46return (cs instanceof IBM834);47}4849public CharsetDecoder newDecoder() {50IBM933.initb2c();51return new DoubleByte.Decoder_DBCSONLY(52this, IBM933.b2c, null, 0x40, 0xfe); // hardcode the b2min/max53}5455public CharsetEncoder newEncoder() {56IBM933.initc2b();57return new Encoder(this);58}5960protected static class Encoder extends DoubleByte.Encoder_DBCSONLY {61public Encoder(Charset cs) {62super(cs, new byte[] {(byte)0xfe, (byte)0xfe},63IBM933.c2b, IBM933.c2bIndex);64}6566public int encodeChar(char ch) {67int bb = super.encodeChar(ch);68if (bb == UNMAPPABLE_ENCODING) {69// Cp834 has 6 additional non-roundtrip char->bytes70// mappings, see#637980871if (ch == '\u00b7') {72return 0x4143;73} else if (ch == '\u00ad') {74return 0x4148;75} else if (ch == '\u2015') {76return 0x4149;77} else if (ch == '\u223c') {78return 0x42a1;79} else if (ch == '\uff5e') {80return 0x4954;81} else if (ch == '\u2299') {82return 0x496f;83}84}85return bb;86}8788public boolean isLegalReplacement(byte[] repl) {89if (repl.length == 2 &&90repl[0] == (byte)0xfe && repl[1] == (byte)0xfe)91return true;92return super.isLegalReplacement(repl);93}9495}96}979899