author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 2913 | 39a9cc073b84 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.io; |
|
27 |
||
28 |
import sun.nio.cs.ext.EUC_TW; |
|
29 |
||
30 |
/* |
|
31 |
* @author Limin Shi |
|
32 |
*/ |
|
33 |
||
34 |
public class CharToByteEUC_TW extends CharToByteConverter |
|
35 |
{ |
|
2913
39a9cc073b84
6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents:
2
diff
changeset
|
36 |
private final EUC_TW.Encoder enc = (EUC_TW.Encoder)(new EUC_TW().newEncoder()); |
2 | 37 |
|
38 |
public int flush(byte[] output, int outStart, int outEnd) |
|
39 |
throws MalformedInputException |
|
40 |
{ |
|
41 |
reset(); |
|
42 |
return 0; |
|
43 |
} |
|
44 |
||
45 |
public void reset() { |
|
46 |
byteOff = charOff = 0; |
|
47 |
} |
|
48 |
||
49 |
public boolean canConvert(char ch){ |
|
2913
39a9cc073b84
6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents:
2
diff
changeset
|
50 |
return enc.canEncode(ch); |
2 | 51 |
} |
52 |
||
53 |
/** |
|
54 |
* Character conversion |
|
55 |
*/ |
|
56 |
public int convert(char[] input, int inOff, int inEnd, |
|
57 |
byte[] output, int outOff, int outEnd) |
|
58 |
throws UnknownCharacterException, MalformedInputException, |
|
59 |
ConversionBufferFullException |
|
60 |
{ |
|
61 |
int outputSize; |
|
2913
39a9cc073b84
6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents:
2
diff
changeset
|
62 |
byte [] tmpbuf = new byte[4];; |
2 | 63 |
byte [] outputByte; |
64 |
byteOff = outOff; |
|
65 |
||
66 |
//Fixed 4122961 by bringing the charOff++ out to this |
|
67 |
// loop where it belongs, changing the loop from |
|
68 |
// while(){} to for(){}. |
|
69 |
for (charOff = inOff; charOff < inEnd; charOff++) { |
|
70 |
outputByte = tmpbuf; |
|
71 |
if ( input[charOff] < 0x80) { // ASCII |
|
72 |
outputSize = 1; |
|
73 |
outputByte[0] = (byte)(input[charOff] & 0x7f); |
|
74 |
} else { |
|
2913
39a9cc073b84
6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents:
2
diff
changeset
|
75 |
outputSize = enc.toEUC(input[charOff], outputByte); |
2 | 76 |
} |
77 |
||
78 |
if (outputSize == -1) { |
|
79 |
if (subMode) { |
|
80 |
outputByte = subBytes; |
|
81 |
outputSize = subBytes.length; |
|
82 |
} else { |
|
83 |
badInputLength = 1; |
|
84 |
throw new UnknownCharacterException(); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
if (outEnd - byteOff < outputSize) |
|
89 |
throw new ConversionBufferFullException(); |
|
90 |
||
91 |
for (int i = 0; i < outputSize; i++) |
|
92 |
output[byteOff++] = outputByte[i]; |
|
93 |
} |
|
94 |
||
95 |
return byteOff - outOff; |
|
96 |
||
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* returns the maximum number of bytes needed to convert a char |
|
101 |
*/ |
|
102 |
public int getMaxBytesPerChar() { |
|
103 |
return 4; |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Return the character set ID |
|
108 |
*/ |
|
109 |
public String getCharacterEncoding() { |
|
110 |
return "EUC_TW"; |
|
111 |
} |
|
112 |
} |