jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/SimpleEUCEncoder.java
author kshefov
Fri, 19 Sep 2014 13:00:17 +0400
changeset 26718 d0a67c728876
parent 25859 3317bb8137f4
permissions -rw-r--r--
8058635: [TEST_BUG] sun/awt/datatransfer/SuplementaryCharactersTransferTest.java fails with Compilation error Reviewed-by: serb, alexsch Contributed-by: pooja.chopra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
     2
 * Copyright (c) 2003, 2006, 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: 3714
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: 3714
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: 3714
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package sun.nio.cs.ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.charset.CoderResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.nio.cs.Surrogate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public abstract class SimpleEUCEncoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    extends CharsetEncoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected short  index1[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected String index2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    protected String index2a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    protected String index2b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    protected String index2c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected int    mask1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected int    mask2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected int    shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private byte[] outputByte = new byte[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final Surrogate.Parser sgp = new Surrogate.Parser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected SimpleEUCEncoder(Charset cs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super(cs, 3.0f, 4.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Returns true if the given character can be converted to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * target character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public boolean canEncode(char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
       int    index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
       String theChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
       index = index1[((ch & mask1) >> shift)] + (ch & mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
       if (index < 7500)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         theChars = index2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
       else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         if (index < 15000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
           index = index - 7500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
           theChars = index2a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
           if (index < 22500){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
             index = index - 15000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             theChars = index2b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
           else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
             index = index - 22500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
             theChars = index2c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
       if (theChars.charAt(2*index) != '\u0000' ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    theChars.charAt(2*index + 1) != '\u0000')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         return (true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
       // only return true if input char was unicode null - all others are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
       //     undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
       return( ch == '\u0000');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        char[] sa = src.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int sp = src.arrayOffset() + src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int sl = src.arrayOffset() + src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        assert (sp <= sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        sp = (sp <= sl ? sp : sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        byte[] da = dst.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int dp = dst.arrayOffset() + dst.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        int dl = dst.arrayOffset() + dst.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        assert (dp <= dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        dp = (dp <= dl ? dp : dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        int     index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int     spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int     i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            while (sp < sl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                boolean allZeroes = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                char inputChar = sa[sp];
3714
6a4eb8f53f91 6860431: Character.isSurrogate(char ch)
martin
parents: 2
diff changeset
   117
                if (Character.isSurrogate(inputChar)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    if (sgp.parse(inputChar, sa, sp, sl) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        return sgp.error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    return sgp.unmappableResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (inputChar >= '\uFFFE')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    return CoderResult.unmappableForLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                String theChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                char   aChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                 // We have a valid character, get the bytes for it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                index = index1[((inputChar & mask1) >> shift)] + (inputChar & mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (index < 7500)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    theChars = index2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                else if (index < 15000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                     index = index - 7500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                     theChars = index2a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                } else if (index < 22500){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    index = index - 15000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    theChars = index2b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    index = index - 22500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    theChars = index2c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                aChar = theChars.charAt(2*index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                outputByte[0] = (byte)((aChar & 0xff00)>>8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                outputByte[1] = (byte)(aChar & 0x00ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                aChar = theChars.charAt(2*index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                outputByte[2] = (byte)((aChar & 0xff00)>>8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                outputByte[3] = (byte)(aChar & 0x00ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            for (i = 0; i < outputByte.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                if (outputByte[i] != 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                allZeroes = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            if (allZeroes && inputChar != '\u0000') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                return CoderResult.unmappableForLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            int oindex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            for (spaceNeeded = outputByte.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                 spaceNeeded > 1; spaceNeeded--){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (outputByte[oindex++] != 0x00 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (dp + spaceNeeded > dl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            for (i = outputByte.length - spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                 i < outputByte.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    da[dp++] = outputByte[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            src.position(sp - src.arrayOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            dst.position(dp - dst.arrayOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        int     index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int     spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        int     i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        int mark = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            while (src.hasRemaining()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                char inputChar = src.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                boolean allZeroes = true;
3714
6a4eb8f53f91 6860431: Character.isSurrogate(char ch)
martin
parents: 2
diff changeset
   197
                if (Character.isSurrogate(inputChar)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    if (sgp.parse(inputChar, src) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        return sgp.error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    return sgp.unmappableResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if (inputChar >= '\uFFFE')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    return CoderResult.unmappableForLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                String theChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                char   aChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                 // We have a valid character, get the bytes for it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                index = index1[((inputChar & mask1) >> shift)] + (inputChar & mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (index < 7500)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    theChars = index2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                else if (index < 15000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                     index = index - 7500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                     theChars = index2a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                } else if (index < 22500){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    index = index - 15000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    theChars = index2b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    index = index - 22500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    theChars = index2c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                aChar = theChars.charAt(2*index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                outputByte[0] = (byte)((aChar & 0xff00)>>8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                outputByte[1] = (byte)(aChar & 0x00ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                aChar = theChars.charAt(2*index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                outputByte[2] = (byte)((aChar & 0xff00)>>8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                outputByte[3] = (byte)(aChar & 0x00ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            for (i = 0; i < outputByte.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                if (outputByte[i] != 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                allZeroes = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (allZeroes && inputChar != '\u0000') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                return CoderResult.unmappableForLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            int oindex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            for (spaceNeeded = outputByte.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                 spaceNeeded > 1; spaceNeeded--){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                if (outputByte[oindex++] != 0x00 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (dst.remaining() < spaceNeeded)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            for (i = outputByte.length - spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                 i < outputByte.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    dst.put(outputByte[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            mark++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            src.position(mark);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (true && src.hasArray() && dst.hasArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return encodeArrayLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            return encodeBufferLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public byte encode(char inputChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return (byte)index2.charAt(index1[(inputChar & mask1) >> shift] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                (inputChar & mask2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}