author | jwilhelm |
Thu, 12 Sep 2019 03:21:11 +0200 | |
changeset 58094 | 0f6c749acd15 |
parent 52880 | c56c30f9f991 |
permissions | -rw-r--r-- |
52880
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
1 |
/* |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
4 |
* |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
10 |
* |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
15 |
* accompanied this code). |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
16 |
* |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
20 |
* |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
23 |
* questions. |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
24 |
*/ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
25 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
26 |
/* |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
27 |
*/ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
28 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
29 |
package $PACKAGE$; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
30 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
31 |
import java.nio.ByteBuffer; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
32 |
import java.nio.CharBuffer; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
33 |
import java.nio.charset.Charset; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
34 |
import java.nio.charset.CharsetEncoder; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
35 |
import java.nio.charset.CoderResult; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
36 |
import sun.nio.cs.Surrogate; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
37 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
38 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
39 |
public abstract class SimpleEUCEncoder |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
40 |
extends CharsetEncoder |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
41 |
{ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
42 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
43 |
protected short index1[]; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
44 |
protected String index2; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
45 |
protected String index2a; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
46 |
protected String index2b; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
47 |
protected String index2c; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
48 |
protected int mask1; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
49 |
protected int mask2; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
50 |
protected int shift; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
51 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
52 |
private byte[] outputByte = new byte[4]; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
53 |
private final Surrogate.Parser sgp = new Surrogate.Parser(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
54 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
55 |
protected SimpleEUCEncoder(Charset cs) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
56 |
{ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
57 |
super(cs, 3.0f, 4.0f); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
58 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
59 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
60 |
/** |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
61 |
* Returns true if the given character can be converted to the |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
62 |
* target character encoding. |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
63 |
*/ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
64 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
65 |
public boolean canEncode(char ch) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
66 |
int index; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
67 |
String theChars; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
68 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
69 |
index = index1[((ch & mask1) >> shift)] + (ch & mask2); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
70 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
71 |
if (index < 7500) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
72 |
theChars = index2; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
73 |
else |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
74 |
if (index < 15000) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
75 |
index = index - 7500; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
76 |
theChars = index2a; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
77 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
78 |
else |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
79 |
if (index < 22500){ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
80 |
index = index - 15000; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
81 |
theChars = index2b; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
82 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
83 |
else { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
84 |
index = index - 22500; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
85 |
theChars = index2c; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
86 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
87 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
88 |
if (theChars.charAt(2*index) != '\u0000' || |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
89 |
theChars.charAt(2*index + 1) != '\u0000') |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
90 |
return (true); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
91 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
92 |
// only return true if input char was unicode null - all others are |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
93 |
// undefined |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
94 |
return( ch == '\u0000'); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
95 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
96 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
97 |
private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
98 |
char[] sa = src.array(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
99 |
int sp = src.arrayOffset() + src.position(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
100 |
int sl = src.arrayOffset() + src.limit(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
101 |
assert (sp <= sl); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
102 |
sp = (sp <= sl ? sp : sl); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
103 |
byte[] da = dst.array(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
104 |
int dp = dst.arrayOffset() + dst.position(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
105 |
int dl = dst.arrayOffset() + dst.limit(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
106 |
assert (dp <= dl); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
107 |
dp = (dp <= dl ? dp : dl); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
108 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
109 |
int index; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
110 |
int spaceNeeded; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
111 |
int i; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
112 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
113 |
try { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
114 |
while (sp < sl) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
115 |
boolean allZeroes = true; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
116 |
char inputChar = sa[sp]; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
117 |
if (Character.isSurrogate(inputChar)) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
118 |
if (sgp.parse(inputChar, sa, sp, sl) < 0) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
119 |
return sgp.error(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
120 |
return sgp.unmappableResult(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
121 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
122 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
123 |
if (inputChar >= '\uFFFE') |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
124 |
return CoderResult.unmappableForLength(1); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
125 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
126 |
String theChars; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
127 |
char aChar; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
128 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
129 |
// We have a valid character, get the bytes for it |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
130 |
index = index1[((inputChar & mask1) >> shift)] + (inputChar & mask2); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
131 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
132 |
if (index < 7500) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
133 |
theChars = index2; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
134 |
else if (index < 15000) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
135 |
index = index - 7500; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
136 |
theChars = index2a; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
137 |
} else if (index < 22500){ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
138 |
index = index - 15000; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
139 |
theChars = index2b; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
140 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
141 |
else { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
142 |
index = index - 22500; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
143 |
theChars = index2c; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
144 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
145 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
146 |
aChar = theChars.charAt(2*index); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
147 |
outputByte[0] = (byte)((aChar & 0xff00)>>8); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
148 |
outputByte[1] = (byte)(aChar & 0x00ff); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
149 |
aChar = theChars.charAt(2*index + 1); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
150 |
outputByte[2] = (byte)((aChar & 0xff00)>>8); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
151 |
outputByte[3] = (byte)(aChar & 0x00ff); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
152 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
153 |
for (i = 0; i < outputByte.length; i++) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
154 |
if (outputByte[i] != 0x00) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
155 |
allZeroes = false; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
156 |
break; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
157 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
158 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
159 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
160 |
if (allZeroes && inputChar != '\u0000') { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
161 |
return CoderResult.unmappableForLength(1); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
162 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
163 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
164 |
int oindex = 0; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
165 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
166 |
for (spaceNeeded = outputByte.length; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
167 |
spaceNeeded > 1; spaceNeeded--){ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
168 |
if (outputByte[oindex++] != 0x00 ) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
169 |
break; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
170 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
171 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
172 |
if (dp + spaceNeeded > dl) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
173 |
return CoderResult.OVERFLOW; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
174 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
175 |
for (i = outputByte.length - spaceNeeded; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
176 |
i < outputByte.length; i++) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
177 |
da[dp++] = outputByte[i]; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
178 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
179 |
sp++; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
180 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
181 |
return CoderResult.UNDERFLOW; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
182 |
} finally { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
183 |
src.position(sp - src.arrayOffset()); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
184 |
dst.position(dp - dst.arrayOffset()); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
185 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
186 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
187 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
188 |
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
189 |
int index; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
190 |
int spaceNeeded; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
191 |
int i; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
192 |
int mark = src.position(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
193 |
try { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
194 |
while (src.hasRemaining()) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
195 |
char inputChar = src.get(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
196 |
boolean allZeroes = true; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
197 |
if (Character.isSurrogate(inputChar)) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
198 |
if (sgp.parse(inputChar, src) < 0) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
199 |
return sgp.error(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
200 |
return sgp.unmappableResult(); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
201 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
202 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
203 |
if (inputChar >= '\uFFFE') |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
204 |
return CoderResult.unmappableForLength(1); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
205 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
206 |
String theChars; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
207 |
char aChar; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
208 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
209 |
// We have a valid character, get the bytes for it |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
210 |
index = index1[((inputChar & mask1) >> shift)] + (inputChar & mask2); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
211 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
212 |
if (index < 7500) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
213 |
theChars = index2; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
214 |
else if (index < 15000) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
215 |
index = index - 7500; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
216 |
theChars = index2a; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
217 |
} else if (index < 22500){ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
218 |
index = index - 15000; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
219 |
theChars = index2b; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
220 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
221 |
else { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
222 |
index = index - 22500; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
223 |
theChars = index2c; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
224 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
225 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
226 |
aChar = theChars.charAt(2*index); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
227 |
outputByte[0] = (byte)((aChar & 0xff00)>>8); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
228 |
outputByte[1] = (byte)(aChar & 0x00ff); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
229 |
aChar = theChars.charAt(2*index + 1); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
230 |
outputByte[2] = (byte)((aChar & 0xff00)>>8); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
231 |
outputByte[3] = (byte)(aChar & 0x00ff); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
232 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
233 |
for (i = 0; i < outputByte.length; i++) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
234 |
if (outputByte[i] != 0x00) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
235 |
allZeroes = false; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
236 |
break; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
237 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
238 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
239 |
if (allZeroes && inputChar != '\u0000') { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
240 |
return CoderResult.unmappableForLength(1); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
241 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
242 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
243 |
int oindex = 0; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
244 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
245 |
for (spaceNeeded = outputByte.length; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
246 |
spaceNeeded > 1; spaceNeeded--){ |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
247 |
if (outputByte[oindex++] != 0x00 ) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
248 |
break; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
249 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
250 |
if (dst.remaining() < spaceNeeded) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
251 |
return CoderResult.OVERFLOW; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
252 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
253 |
for (i = outputByte.length - spaceNeeded; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
254 |
i < outputByte.length; i++) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
255 |
dst.put(outputByte[i]); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
256 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
257 |
mark++; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
258 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
259 |
return CoderResult.UNDERFLOW; |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
260 |
} finally { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
261 |
src.position(mark); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
262 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
263 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
264 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
265 |
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
266 |
if (true && src.hasArray() && dst.hasArray()) |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
267 |
return encodeArrayLoop(src, dst); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
268 |
else |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
269 |
return encodeBufferLoop(src, dst); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
270 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
271 |
|
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
272 |
public byte encode(char inputChar) { |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
273 |
return (byte)index2.charAt(index1[(inputChar & mask1) >> shift] + |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
274 |
(inputChar & mask2)); |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
275 |
} |
c56c30f9f991
8212794: IBM-964 is required for AIX default charset
itakiguchi
parents:
diff
changeset
|
276 |
} |