0N/A/*
2362N/A * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A */
0N/A
0N/Apackage sun.nio.cs.ext;
0N/A
0N/Aimport java.nio.charset.Charset;
0N/Aimport java.nio.ByteBuffer;
0N/Aimport java.nio.CharBuffer;
0N/Aimport java.nio.charset.CharsetDecoder;
0N/Aimport java.nio.charset.CharsetEncoder;
0N/Aimport java.nio.charset.CoderResult;
0N/Aimport sun.nio.cs.HistoricallyNamedCharset;
0N/A
0N/Apublic class ISO2022_CN_GB extends ISO2022 implements HistoricallyNamedCharset
0N/A{
0N/A public ISO2022_CN_GB() {
0N/A super("x-ISO-2022-CN-GB",
0N/A ExtendedCharsets.aliasesFor("x-ISO-2022-CN-GB"));
0N/A }
0N/A
0N/A public boolean contains(Charset cs) {
0N/A // overlapping repertoire of EUC_CN, GB2312
0N/A return ((cs instanceof EUC_CN) ||
0N/A (cs.name().equals("US-ASCII")) ||
0N/A (cs instanceof ISO2022_CN_GB));
0N/A }
0N/A
0N/A public String historicalName() {
0N/A return "ISO2022CN_GB";
0N/A }
0N/A
0N/A public CharsetDecoder newDecoder() {
0N/A return new ISO2022_CN.Decoder(this);
0N/A }
0N/A
0N/A public CharsetEncoder newEncoder() {
0N/A return new Encoder(this);
0N/A }
0N/A
0N/A private static class Encoder extends ISO2022.Encoder {
0N/A
0N/A public Encoder(Charset cs)
0N/A {
0N/A super(cs);
0N/A SODesig = "$)A";
0N/A
0N/A try {
0N/A Charset cset = Charset.forName("EUC_CN"); // GB2312
0N/A ISOEncoder = cset.newEncoder();
0N/A } catch (Exception e) { }
0N/A }
0N/A
0N/A /*
0N/A * Since ISO2022-CN-GB possesses a CharsetEncoder
0N/A * without the corresponding CharsetDecoder half the
0N/A * default replacement check needs to be overridden
0N/A * since the parent class version attempts to
0N/A * decode 0x3f (?).
0N/A */
0N/A
0N/A public boolean isLegalReplacement(byte[] repl) {
0N/A // 0x3f is OK as the replacement byte
0N/A return (repl.length == 1 && repl[0] == (byte) 0x3f);
0N/A }
0N/A }
0N/A}