jdk/src/share/classes/sun/io/CharToByteSingleByte.java
author sherman
Wed, 10 Dec 2008 14:03:15 -0800
changeset 1713 f8b8bfa64fc1
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6642323: Speeding up Single Byte Decoders 6642328: Speeding up Single Byte Encoders Summary: re-implementation of mapping based sbcs charts Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
     2
 * Copyright 1996-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    28
import static sun.nio.cs.CharsetMapping.*;
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
* A table driven conversion from char to byte for single byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
* character sets.  Tables will reside in the class CharToByteYYYYY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
* where YYYYY is a unique character set identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    < TBD: Tables are of the form... >
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
* @author Lloyd Honomichl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
* @author Asmus Freytag
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    40
* @version 8/28/96
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public abstract class CharToByteSingleByte extends CharToByteConverter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * 1st level index, provided by subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    48
    protected char[] index1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * 2nd level index, provided by subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    53
    protected char[] index2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Mask to isolate bits for 1st level index, from subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected int   mask1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Mask to isolate bits for 2nd level index, from subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected int   mask2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Shift to isolate bits for 1st level index, from subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected int   shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private char highHalfZoneCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    72
    public char[] getIndex1() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return index1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
    76
    public char[] getIndex2() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return index2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public int flush(byte[] output, int outStart, int outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        throws MalformedInputException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (highHalfZoneCode != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            highHalfZoneCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            badInputLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new MalformedInputException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        byteOff = charOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Converts characters to sequences of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Conversions that result in Exceptions can be restarted by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * convert again, with appropriately modified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return the characters written to output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param input char array containing text in Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param inStart offset in input array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param inEnd offset of last byte to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param output byte array to receive conversion result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param outStart starting offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param outEnd offset of last byte to be written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @throw MalformedInputException for any sequence of chars that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * illegal in Unicode (principally unpaired surrogates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * and \uFFFF or \uFFFE), including any partial surrogate pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * which occurs at the end of an input buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throw UnsupportedCharacterException for any character that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * that cannot be converted to the external character set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public int convert(char[] input, int inOff, int inEnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                       byte[] output, int outOff, int outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        throws MalformedInputException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
               UnknownCharacterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
               ConversionBufferFullException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        char    inputChar;          // Input character to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        byte[]  outputByte;         // Output byte written to output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int     inputSize;          // Size of input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        int     outputSize;         // Size of output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        byte[]  tmpArray = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // Record beginning offsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        charOff = inOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        byteOff = outOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (highHalfZoneCode != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            inputChar = highHalfZoneCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            highHalfZoneCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            if (input[inOff] >= 0xdc00 && input[inOff] <= 0xdfff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                // This is legal UTF16 sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                badInputLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                throw new UnknownCharacterException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                // This is illegal UTF16 sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                badInputLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                throw new MalformedInputException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // Loop until we hit the end of the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        while(charOff < inEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            outputByte = tmpArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            // Get the input character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            inputChar = input[charOff];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            // Default output size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            outputSize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            // Assume this is a simple character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            inputSize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // Is this a high surrogate?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if(inputChar >= '\uD800' && inputChar <= '\uDBFF') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // Is this the last character in the input?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                if (charOff + 1 >= inEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    highHalfZoneCode = inputChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                // Is there a low surrogate following?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                inputChar = input[charOff + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                if (inputChar >= '\uDC00' && inputChar <= '\uDFFF') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    // We have a valid surrogate pair.  Too bad we don't map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    //  surrogates.  Is substitution enabled?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    if (subMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        outputByte = subBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        outputSize = subBytes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        inputSize = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        badInputLength = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        throw new UnknownCharacterException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    // We have a malformed surrogate pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    badInputLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    throw new MalformedInputException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // Is this an unaccompanied low surrogate?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            else if (inputChar >= '\uDC00' && inputChar <= '\uDFFF') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                badInputLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                throw new MalformedInputException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // Not part of a surrogate, so look it up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                // Get output using two level lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                outputByte[0] = getNative(inputChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                // Might this character be unmappable?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                if (outputByte[0] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    // If outputByte is zero because the input was zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    //  then this character is actually mappable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    if (input[charOff] != '\u0000') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        // We have an unmappable character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        // Is substitution enabled?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        if (subMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                            outputByte = subBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                            outputSize = subBytes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                            badInputLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                            throw new UnknownCharacterException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // If we don't have room for the output, throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (byteOff + outputSize > outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                throw new ConversionBufferFullException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            // Put the byte in the output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            for (int i = 0; i < outputSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                output[byteOff++] = outputByte[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            charOff += inputSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // Return the length written to the output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return byteOff - outOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * the maximum number of bytes needed to hold a converted char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @returns the maximum number of bytes needed for a converted char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public int getMaxBytesPerChar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   235
    int encodeChar(char ch) {
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   236
        char index = index1[ch >> 8];
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   237
        if (index == UNMAPPABLE_ENCODING)
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   238
            return UNMAPPABLE_ENCODING;
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   239
        return index2[index + (ch & 0xff)];
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   240
    }
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   241
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public byte getNative(char inputChar) {
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   243
        int b = encodeChar(inputChar);
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   244
        if (b == UNMAPPABLE_ENCODING)
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   245
            return 0;
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   246
        return (byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *  Resets the converter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Call this method to reset the converter to its initial state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        byteOff = charOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        highHalfZoneCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Return whether a character is mappable or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return true if a character is mappable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public boolean canConvert(char ch) {
1713
f8b8bfa64fc1 6642323: Speeding up Single Byte Decoders
sherman
parents: 2
diff changeset
   263
        return encodeChar(ch) != UNMAPPABLE_ENCODING;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}