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