src/jdk.charsets/share/classes/sun/nio/cs/ext/JISAutoDetect.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 32038 jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/JISAutoDetect.java@911671c0c520
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:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5785
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
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: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.cs.ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.charset.CharsetDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.CoderResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.charset.CharacterCodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.charset.MalformedInputException;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 25859
diff changeset
    36
import sun.nio.cs.DelegatableDecoder;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.nio.cs.HistoricallyNamedCharset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessController;
23582
d5fa3327ab3a 8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents: 7668
diff changeset
    39
import java.security.PrivilegedAction;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 25859
diff changeset
    40
import sun.nio.cs.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import static java.lang.Character.UnicodeBlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class JISAutoDetect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    extends Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    implements HistoricallyNamedCharset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final static int EUCJP_MASK       = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final static int SJIS2B_MASK      = 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final static int SJIS1B_MASK      = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final static int EUCJP_KANA1_MASK = 0x08;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final static int EUCJP_KANA2_MASK = 0x10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public JISAutoDetect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super("x-JISAutoDetect", ExtendedCharsets.aliasesFor("x-JISAutoDetect"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public boolean contains(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return ((cs.name().equals("US-ASCII"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                || (cs instanceof SJIS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                || (cs instanceof EUC_JP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                || (cs instanceof ISO2022_JP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public boolean canEncode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public CharsetDecoder newDecoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return new Decoder(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public String historicalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return "JISAutoDetect";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public CharsetEncoder newEncoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // A heuristic algorithm for guessing if EUC-decoded text really
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // might be Japanese text.  Better heuristics are possible...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static boolean looksLikeJapanese(CharBuffer cb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int hiragana = 0;       // Fullwidth Hiragana
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        int katakana = 0;       // Halfwidth Katakana
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        while (cb.hasRemaining()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            char c = cb.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (0x3040 <= c && c <= 0x309f && ++hiragana > 1) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (0xff65 <= c && c <= 0xff9f && ++katakana > 1) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static class Decoder extends CharsetDecoder {
23587
55ccc7b19f84 8038451: Incorrect initialization order of static fields in sun.nio.cs.ext.JISAutoDetect$Decoder
mchung
parents: 23582
diff changeset
    96
        private final static String osName = AccessController.doPrivileged(
55ccc7b19f84 8038451: Incorrect initialization order of static fields in sun.nio.cs.ext.JISAutoDetect$Decoder
mchung
parents: 23582
diff changeset
    97
            (PrivilegedAction<String>) () -> System.getProperty("os.name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        private final static String SJISName = getSJISName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        private final static String EUCJPName = getEUCJPName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        private DelegatableDecoder detectedDecoder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        public Decoder(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            super(cs, 0.5f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        private static boolean isPlainASCII(byte b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return b >= 0 && b != 0x1b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        private static void copyLeadingASCII(ByteBuffer src, CharBuffer dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            int start = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            int limit = start + Math.min(src.remaining(), dst.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            int p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            byte b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            for (p = start; p < limit && isPlainASCII(b = src.get(p)); p++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                dst.put((char)(b & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            src.position(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   121
        private CoderResult decodeLoop(DelegatableDecoder decoder,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                       ByteBuffer src, CharBuffer dst) {
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   123
            ((CharsetDecoder)decoder).reset();
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   124
            detectedDecoder = decoder;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return detectedDecoder.decodeLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            if (detectedDecoder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                copyLeadingASCII(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                // All ASCII?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (! src.hasRemaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    return CoderResult.UNDERFLOW;
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   135
                // Overflow only if there is still ascii but no out buffer.
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   136
                if (!dst.hasRemaining() &&
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   137
                    isPlainASCII(src.get(src.position())))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                // We need to perform double, not float, arithmetic; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                // we lose low order bits when src is larger than 2**24.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                int cbufsiz = (int)(src.limit() * (double)maxCharsPerByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                CharBuffer sandbox = CharBuffer.allocate(cbufsiz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                // First try ISO-2022-JP, since there is no ambiguity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                Charset cs2022 = Charset.forName("ISO-2022-JP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                DelegatableDecoder dd2022
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    = (DelegatableDecoder) cs2022.newDecoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                ByteBuffer src2022 = src.asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                CoderResult res2022 = dd2022.decodeLoop(src2022, sandbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                if (! res2022.isError())
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   152
                    return decodeLoop(dd2022, src, dst);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                // We must choose between EUC and SJIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                Charset csEUCJ = Charset.forName(EUCJPName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                Charset csSJIS = Charset.forName(SJISName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                DelegatableDecoder ddEUCJ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    = (DelegatableDecoder) csEUCJ.newDecoder();
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   160
                DelegatableDecoder ddSJIS
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   161
                    = (DelegatableDecoder) csSJIS.newDecoder();
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   162
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                ByteBuffer srcEUCJ = src.asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                sandbox.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                CoderResult resEUCJ = ddEUCJ.decodeLoop(srcEUCJ, sandbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                // If EUC decoding fails, must be SJIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                if (resEUCJ.isError())
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   168
                    return decodeLoop(ddSJIS, src, dst);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                ByteBuffer srcSJIS = src.asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                CharBuffer sandboxSJIS = CharBuffer.allocate(cbufsiz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                CoderResult resSJIS = ddSJIS.decodeLoop(srcSJIS, sandboxSJIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                // If SJIS decoding fails, must be EUC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (resSJIS.isError())
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   174
                    return decodeLoop(ddEUCJ, src, dst);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                // From here on, we have some ambiguity, and must guess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                // We prefer input that does not appear to end mid-character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                if (srcEUCJ.position() > srcSJIS.position())
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   180
                    return decodeLoop(ddEUCJ, src, dst);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                if (srcEUCJ.position() < srcSJIS.position())
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   183
                    return decodeLoop(ddSJIS, src, dst);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                // end-of-input is after the first byte of the first char?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if (src.position() == srcEUCJ.position())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                // Use heuristic knowledge of typical Japanese text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                sandbox.flip();
32038
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   191
                return decodeLoop(looksLikeJapanese(sandbox) ? ddEUCJ : ddSJIS,
911671c0c520 8022224: Rare bug in JISAutodetect charset detected by FindDecoderBugs test
sherman
parents: 28969
diff changeset
   192
                                  src, dst);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return detectedDecoder.decodeLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        protected void implReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            detectedDecoder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        protected CoderResult implFlush(CharBuffer out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (detectedDecoder != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                return detectedDecoder.implFlush(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                return super.implFlush(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        public boolean isAutoDetecting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        public boolean isCharsetDetected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return detectedDecoder != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        public Charset detectedCharset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (detectedDecoder == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                throw new IllegalStateException("charset not yet detected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return ((CharsetDecoder) detectedDecoder).charset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
23582
d5fa3327ab3a 8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents: 7668
diff changeset
   223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         * Returned Shift_JIS Charset name is OS dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        private static String getSJISName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (osName.equals("Solaris") || osName.equals("SunOS"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                return("PCK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            else if (osName.startsWith("Windows"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                return("windows-31J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                return("Shift_JIS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * Returned EUC-JP Charset name is OS dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        private static String getEUCJPName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (osName.equals("Solaris") || osName.equals("SunOS"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return("x-eucjp-open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                return("EUC_JP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}