jdk/src/share/classes/sun/io/CharToByteDBCS_EBCDIC.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3714 6a4eb8f53f91
child 5986 04eb44085c00
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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) 1997, 1999, 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
package sun.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    27
import sun.nio.cs.Surrogate;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    28
import sun.nio.cs.ext.DoubleByte;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    29
import static sun.nio.cs.CharsetMapping.*;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public abstract class CharToByteDBCS_EBCDIC extends CharToByteConverter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private static final int SBCS = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private static final int DBCS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static final byte SO = 0x0e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static final byte SI = 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private int  currentState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private char highHalfZoneCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private byte[] outputByte = new byte[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    43
    private DoubleByte.Encoder enc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    45
    public CharToByteDBCS_EBCDIC(DoubleByte.Encoder enc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        highHalfZoneCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        currentState = SBCS;
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    49
        this.enc = enc;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    50
    }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    51
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    52
    int encodeChar(char c) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
    53
        return enc.encodeChar(c);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
      * flush out any residual data and reset the buffer state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public int flush(byte [] output, int outStart, int outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        throws MalformedInputException, ConversionBufferFullException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int bytesOut = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (highHalfZoneCode != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            badInputLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            throw new MalformedInputException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (currentState == DBCS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
          if (outStart >= outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            throw new ConversionBufferFullException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
          output[outStart] = SI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
          bytesOut++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return bytesOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Character conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public int convert(char[] input, int inOff, int inEnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                       byte[] output, int outOff, int outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        throws UnknownCharacterException, MalformedInputException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
               ConversionBufferFullException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        char    inputChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int     inputSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        byteOff = outOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        charOff = inOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        while(charOff < inEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
           int   index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
           int   theBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
           int   spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
           if (highHalfZoneCode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
              inputChar = input[charOff];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
              inputSize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
           } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
              inputChar = highHalfZoneCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
              inputSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
              highHalfZoneCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
           // Is this a high surrogate?
3714
6a4eb8f53f91 6860431: Character.isSurrogate(char ch)
martin
parents: 2921
diff changeset
   111
           if (Character.isHighSurrogate(inputChar)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
              // Is this the last character of the input?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              if (charOff + inputSize >= inEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                 highHalfZoneCode = inputChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                 charOff += inputSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                 break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
              // Is there a low surrogate following?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
              inputChar = input[charOff + inputSize];
3714
6a4eb8f53f91 6860431: Character.isSurrogate(char ch)
martin
parents: 2921
diff changeset
   121
              if (Character.isLowSurrogate(inputChar)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                 // We have a valid surrogate pair.  Too bad we don't do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                 // surrogates.  Is substitution enabled?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                 if (subMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    if (subBytes.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                       outputByte[0] = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                       outputByte[1] = subBytes[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                       outputByte[0] = subBytes[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                       outputByte[1] = subBytes[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    inputSize++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                 } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    badInputLength = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    throw new UnknownCharacterException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                 // We have a malformed surrogate pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                 badInputLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                 throw new MalformedInputException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
           // Is this an unaccompanied low surrogate?
3714
6a4eb8f53f91 6860431: Character.isSurrogate(char ch)
martin
parents: 2921
diff changeset
   145
           else if (Character.isLowSurrogate(inputChar)) {
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   146
               badInputLength = 1;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   147
               throw new MalformedInputException();
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   148
           } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   150
               // We have a valid character, get the bytes for it
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   151
               theBytes = encodeChar(inputChar);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   152
               if (theBytes == UNMAPPABLE_ENCODING) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   153
                   // if there was no mapping - look for substitution characters
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   154
                   if (subMode) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   155
                       if (subBytes.length == 1) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   156
                           outputByte[0] = 0x00;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   157
                           outputByte[1] = subBytes[0];
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   158
                       } else {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   159
                           outputByte[0] = subBytes[0];
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   160
                           outputByte[1] = subBytes[1];
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   161
                       }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   162
                   } else {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   163
                       badInputLength = 1;
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   164
                       throw new UnknownCharacterException();
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   165
                   }
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   166
               } else {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   167
                   outputByte[0] = (byte)((theBytes & 0x0000ff00)>>8);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   168
                   outputByte[1] = (byte)(theBytes & 0x000000ff);
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   169
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
           //Set the output buffer into the correct state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
           if (currentState == DBCS && outputByte[0] == 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
              if (byteOff >= outEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                 throw new ConversionBufferFullException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
              currentState = SBCS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
              output[byteOff++] = SI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
           } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
              if (currentState == SBCS && outputByte[0] != 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                 if (byteOff >= outEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    throw new ConversionBufferFullException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                 currentState = DBCS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                 output[byteOff++] = SO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
           if (currentState == DBCS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
              spaceNeeded = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
           else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
              spaceNeeded = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
           if (byteOff + spaceNeeded > outEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
              throw new ConversionBufferFullException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
           if (currentState == SBCS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
              output[byteOff++] = outputByte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
           else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
              output[byteOff++] = outputByte[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
              output[byteOff++] = outputByte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
           charOff += inputSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return byteOff - outOff;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Resets converter to its initial state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
       charOff = byteOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
       highHalfZoneCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
       currentState = SBCS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Returns the maximum number of bytes needed to convert a char.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public int getMaxBytesPerChar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
       return 4;    //Fixed with bug 4199599 so tests would pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Sets the substitution bytes to use when the converter is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * substitution mode.  The given bytes should represent a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * character in the target character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void setSubstitutionBytes( byte[] newSubBytes )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
       throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
       if( newSubBytes.length > 2 || newSubBytes.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
           throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
       subBytes = new byte[ newSubBytes.length ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
       System.arraycopy( newSubBytes, 0, subBytes, 0, newSubBytes.length );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
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
     * Returns true if the given character can be converted to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * target character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
2921
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   251
    public boolean canConvert(char c) {
d9d491a5a169 6843578: Re-implement IBM doublebyte charsets
sherman
parents: 2
diff changeset
   252
        return encodeChar(c) != UNMAPPABLE_ENCODING;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}