author | dholmes |
Mon, 09 Jul 2018 20:17:32 -0400 | |
changeset 51020 | 1835f9fca157 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
1 |
/* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
4 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
10 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
15 |
* accompanied this code). |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
16 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
20 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
23 |
* questions. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
24 |
*/ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
25 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
26 |
package $PACKAGE$; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
27 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
28 |
import java.nio.ByteBuffer; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
29 |
import java.nio.CharBuffer; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
30 |
import java.nio.charset.Charset; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
31 |
import java.nio.charset.CharsetDecoder; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
32 |
import java.nio.charset.CharsetEncoder; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
33 |
import java.nio.charset.CoderResult; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
34 |
import sun.nio.cs.HistoricallyNamedCharset; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
35 |
import sun.nio.cs.DelegatableDecoder; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
36 |
import sun.nio.cs.DoubleByte; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
37 |
import sun.nio.cs.Surrogate; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
38 |
import sun.nio.cs.SingleByte; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
39 |
import sun.nio.cs.*; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
40 |
import static sun.nio.cs.CharsetMapping.*; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
41 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
42 |
public class EUC_JP |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
43 |
extends Charset |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
44 |
implements HistoricallyNamedCharset |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
45 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
46 |
public EUC_JP() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
47 |
super("EUC-JP", $ALIASES$); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
48 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
49 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
50 |
public String historicalName() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
51 |
return "EUC_JP"; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
52 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
53 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
54 |
public boolean contains(Charset cs) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
55 |
return ((cs.name().equals("US-ASCII")) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
56 |
|| (cs instanceof JIS_X_0201) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
57 |
|| (cs instanceof JIS_X_0208) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
58 |
|| (cs instanceof JIS_X_0212) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
59 |
|| (cs instanceof EUC_JP)); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
60 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
61 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
62 |
public CharsetDecoder newDecoder() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
63 |
return new Decoder(this); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
64 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
65 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
66 |
public CharsetEncoder newEncoder() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
67 |
return new Encoder(this); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
68 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
69 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
70 |
static class Decoder extends CharsetDecoder |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
71 |
implements DelegatableDecoder { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
72 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
73 |
final static SingleByte.Decoder DEC0201 = |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
74 |
(SingleByte.Decoder)new JIS_X_0201().newDecoder(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
75 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
76 |
final static DoubleByte.Decoder DEC0208 = |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
77 |
(DoubleByte.Decoder)new JIS_X_0208().newDecoder(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
78 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
79 |
final static DoubleByte.Decoder DEC0212 = |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
80 |
(DoubleByte.Decoder)new JIS_X_0212().newDecoder(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
81 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
82 |
private final SingleByte.Decoder dec0201; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
83 |
private final DoubleByte.Decoder dec0208; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
84 |
private final DoubleByte.Decoder dec0212; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
85 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
86 |
protected Decoder(Charset cs) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
87 |
this(cs, 0.5f, 1.0f, DEC0201, DEC0208, DEC0212); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
88 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
89 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
90 |
protected Decoder(Charset cs, float avgCpb, float maxCpb, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
91 |
SingleByte.Decoder dec0201, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
92 |
DoubleByte.Decoder dec0208, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
93 |
DoubleByte.Decoder dec0212) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
94 |
super(cs, avgCpb, maxCpb); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
95 |
this.dec0201 = dec0201; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
96 |
this.dec0208 = dec0208; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
97 |
this.dec0212 = dec0212; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
98 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
99 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
100 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
101 |
protected char decodeDouble(int byte1, int byte2) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
102 |
if (byte1 == 0x8e) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
103 |
if (byte2 < 0x80) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
104 |
return UNMAPPABLE_DECODING; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
105 |
return dec0201.decode((byte)byte2); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
106 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
107 |
return dec0208.decodeDouble(byte1 - 0x80, byte2 - 0x80); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
108 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
109 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
110 |
private CoderResult decodeArrayLoop(ByteBuffer src, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
111 |
CharBuffer dst) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
112 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
113 |
byte[] sa = src.array(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
114 |
int sp = src.arrayOffset() + src.position(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
115 |
int sl = src.arrayOffset() + src.limit(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
116 |
assert (sp <= sl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
117 |
sp = (sp <= sl ? sp : sl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
118 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
119 |
char[] da = dst.array(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
120 |
int dp = dst.arrayOffset() + dst.position(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
121 |
int dl = dst.arrayOffset() + dst.limit(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
122 |
assert (dp <= dl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
123 |
dp = (dp <= dl ? dp : dl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
124 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
125 |
int b1 = 0, b2 = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
126 |
int inputSize = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
127 |
char outputChar = UNMAPPABLE_DECODING; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
128 |
try { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
129 |
while (sp < sl) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
130 |
b1 = sa[sp] & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
131 |
inputSize = 1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
132 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
133 |
if ((b1 & 0x80) == 0) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
134 |
outputChar = (char)b1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
135 |
} else { // Multibyte char |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
136 |
if (b1 == 0x8f) { // JIS0212 |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
137 |
if (sp + 3 > sl) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
138 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
139 |
b1 = sa[sp + 1] & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
140 |
b2 = sa[sp + 2] & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
141 |
inputSize += 2; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
142 |
if (dec0212 == null) // JIS02012 not supported |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
143 |
return CoderResult.unmappableForLength(inputSize); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
144 |
outputChar = dec0212.decodeDouble(b1-0x80, b2-0x80); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
145 |
} else { // JIS0201, JIS0208 |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
146 |
if (sp + 2 > sl) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
147 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
148 |
b2 = sa[sp + 1] & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
149 |
inputSize++; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
150 |
outputChar = decodeDouble(b1, b2); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
151 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
152 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
153 |
if (outputChar == UNMAPPABLE_DECODING) { // can't be decoded |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
154 |
return CoderResult.unmappableForLength(inputSize); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
155 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
156 |
if (dp + 1 > dl) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
157 |
return CoderResult.OVERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
158 |
da[dp++] = outputChar; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
159 |
sp += inputSize; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
160 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
161 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
162 |
} finally { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
163 |
src.position(sp - src.arrayOffset()); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
164 |
dst.position(dp - dst.arrayOffset()); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
165 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
166 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
167 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
168 |
private CoderResult decodeBufferLoop(ByteBuffer src, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
169 |
CharBuffer dst) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
170 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
171 |
int mark = src.position(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
172 |
int b1 = 0, b2 = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
173 |
int inputSize = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
174 |
char outputChar = UNMAPPABLE_DECODING; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
175 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
176 |
try { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
177 |
while (src.hasRemaining()) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
178 |
b1 = src.get() & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
179 |
inputSize = 1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
180 |
if ((b1 & 0x80) == 0) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
181 |
outputChar = (char)b1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
182 |
} else { // Multibyte char |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
183 |
if (b1 == 0x8f) { // JIS0212 |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
184 |
if (src.remaining() < 2) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
185 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
186 |
b1 = src.get() & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
187 |
b2 = src.get() & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
188 |
inputSize += 2; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
189 |
if (dec0212 == null) // JIS02012 not supported |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
190 |
return CoderResult.unmappableForLength(inputSize); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
191 |
outputChar = dec0212.decodeDouble(b1-0x80, b2-0x80); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
192 |
} else { // JIS0201 JIS0208 |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
193 |
if (src.remaining() < 1) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
194 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
195 |
b2 = src.get() & 0xff; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
196 |
inputSize++; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
197 |
outputChar = decodeDouble(b1, b2); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
198 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
199 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
200 |
if (outputChar == UNMAPPABLE_DECODING) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
201 |
return CoderResult.unmappableForLength(inputSize); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
202 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
203 |
if (dst.remaining() < 1) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
204 |
return CoderResult.OVERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
205 |
dst.put(outputChar); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
206 |
mark += inputSize; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
207 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
208 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
209 |
} finally { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
210 |
src.position(mark); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
211 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
212 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
213 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
214 |
// Make some protected methods public for use by JISAutoDetect |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
215 |
public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
216 |
if (src.hasArray() && dst.hasArray()) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
217 |
return decodeArrayLoop(src, dst); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
218 |
else |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
219 |
return decodeBufferLoop(src, dst); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
220 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
221 |
public void implReset() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
222 |
super.implReset(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
223 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
224 |
public CoderResult implFlush(CharBuffer out) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
225 |
return super.implFlush(out); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
226 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
227 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
228 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
229 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
230 |
static class Encoder extends CharsetEncoder { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
231 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
232 |
final static SingleByte.Encoder ENC0201 = |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
233 |
(SingleByte.Encoder)new JIS_X_0201().newEncoder(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
234 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
235 |
final static DoubleByte.Encoder ENC0208 = |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
236 |
(DoubleByte.Encoder)new JIS_X_0208().newEncoder(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
237 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
238 |
final static DoubleByte.Encoder ENC0212 = |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
239 |
(DoubleByte.Encoder)new JIS_X_0212().newEncoder(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
240 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
241 |
private final Surrogate.Parser sgp = new Surrogate.Parser(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
242 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
243 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
244 |
private final SingleByte.Encoder enc0201; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
245 |
private final DoubleByte.Encoder enc0208; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
246 |
private final DoubleByte.Encoder enc0212; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
247 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
248 |
protected Encoder(Charset cs) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
249 |
this(cs, 3.0f, 3.0f, ENC0201, ENC0208, ENC0212); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
250 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
251 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
252 |
protected Encoder(Charset cs, float avgBpc, float maxBpc, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
253 |
SingleByte.Encoder enc0201, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
254 |
DoubleByte.Encoder enc0208, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
255 |
DoubleByte.Encoder enc0212) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
256 |
super(cs, avgBpc, maxBpc); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
257 |
this.enc0201 = enc0201; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
258 |
this.enc0208 = enc0208; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
259 |
this.enc0212 = enc0212; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
260 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
261 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
262 |
public boolean canEncode(char c) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
263 |
byte[] encodedBytes = new byte[3]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
264 |
return encodeSingle(c, encodedBytes) != 0 || |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
265 |
encodeDouble(c) != UNMAPPABLE_ENCODING; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
266 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
267 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
268 |
protected int encodeSingle(char inputChar, byte[] outputByte) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
269 |
int b = enc0201.encode(inputChar); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
270 |
if (b == UNMAPPABLE_ENCODING) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
271 |
return 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
272 |
if (b >= 0 && b < 128) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
273 |
outputByte[0] = (byte)b; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
274 |
return 1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
275 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
276 |
outputByte[0] = (byte)0x8e; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
277 |
outputByte[1] = (byte)b; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
278 |
return 2; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
279 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
280 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
281 |
protected int encodeDouble(char ch) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
282 |
int b = enc0208.encodeChar(ch); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
283 |
if (b != UNMAPPABLE_ENCODING) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
284 |
return b + 0x8080; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
285 |
if (enc0212 != null) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
286 |
b = enc0212.encodeChar(ch); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
287 |
if (b != UNMAPPABLE_ENCODING) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
288 |
b += 0x8F8080; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
289 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
290 |
return b; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
291 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
292 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
293 |
private CoderResult encodeArrayLoop(CharBuffer src, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
294 |
ByteBuffer dst) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
295 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
296 |
char[] sa = src.array(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
297 |
int sp = src.arrayOffset() + src.position(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
298 |
int sl = src.arrayOffset() + src.limit(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
299 |
assert (sp <= sl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
300 |
sp = (sp <= sl ? sp : sl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
301 |
byte[] da = dst.array(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
302 |
int dp = dst.arrayOffset() + dst.position(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
303 |
int dl = dst.arrayOffset() + dst.limit(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
304 |
assert (dp <= dl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
305 |
dp = (dp <= dl ? dp : dl); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
306 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
307 |
int outputSize = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
308 |
byte[] outputByte; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
309 |
int inputSize = 0; // Size of input |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
310 |
byte[] tmpBuf = new byte[3]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
311 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
312 |
try { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
313 |
while (sp < sl) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
314 |
outputByte = tmpBuf; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
315 |
char c = sa[sp]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
316 |
if (Character.isSurrogate(c)) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
317 |
if (sgp.parse(c, sa, sp, sl) < 0) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
318 |
return sgp.error(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
319 |
return sgp.unmappableResult(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
320 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
321 |
outputSize = encodeSingle(c, outputByte); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
322 |
if (outputSize == 0) { // DoubleByte |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
323 |
int ncode = encodeDouble(c); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
324 |
if (ncode != UNMAPPABLE_ENCODING) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
325 |
if ((ncode & 0xFF0000) == 0) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
326 |
outputByte[0] = (byte) ((ncode & 0xff00) >> 8); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
327 |
outputByte[1] = (byte) (ncode & 0xff); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
328 |
outputSize = 2; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
329 |
} else { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
330 |
outputByte[0] = (byte) 0x8f; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
331 |
outputByte[1] = (byte) ((ncode & 0xff00) >> 8); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
332 |
outputByte[2] = (byte) (ncode & 0xff); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
333 |
outputSize = 3; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
334 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
335 |
} else { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
336 |
return CoderResult.unmappableForLength(1); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
337 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
338 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
339 |
if (dl - dp < outputSize) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
340 |
return CoderResult.OVERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
341 |
// Put the byte in the output buffer |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
342 |
for (int i = 0; i < outputSize; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
343 |
da[dp++] = outputByte[i]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
344 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
345 |
sp++; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
346 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
347 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
348 |
} finally { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
349 |
src.position(sp - src.arrayOffset()); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
350 |
dst.position(dp - dst.arrayOffset()); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
351 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
352 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
353 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
354 |
private CoderResult encodeBufferLoop(CharBuffer src, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
355 |
ByteBuffer dst) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
356 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
357 |
int outputSize = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
358 |
byte[] outputByte; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
359 |
int inputSize = 0; // Size of input |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
360 |
byte[] tmpBuf = new byte[3]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
361 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
362 |
int mark = src.position(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
363 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
364 |
try { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
365 |
while (src.hasRemaining()) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
366 |
outputByte = tmpBuf; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
367 |
char c = src.get(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
368 |
if (Character.isSurrogate(c)) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
369 |
if (sgp.parse(c, src) < 0) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
370 |
return sgp.error(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
371 |
return sgp.unmappableResult(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
372 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
373 |
outputSize = encodeSingle(c, outputByte); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
374 |
if (outputSize == 0) { // DoubleByte |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
375 |
int ncode = encodeDouble(c); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
376 |
if (ncode != UNMAPPABLE_ENCODING) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
377 |
if ((ncode & 0xFF0000) == 0) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
378 |
outputByte[0] = (byte) ((ncode & 0xff00) >> 8); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
379 |
outputByte[1] = (byte) (ncode & 0xff); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
380 |
outputSize = 2; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
381 |
} else { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
382 |
outputByte[0] = (byte) 0x8f; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
383 |
outputByte[1] = (byte) ((ncode & 0xff00) >> 8); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
384 |
outputByte[2] = (byte) (ncode & 0xff); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
385 |
outputSize = 3; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
386 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
387 |
} else { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
388 |
return CoderResult.unmappableForLength(1); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
389 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
390 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
391 |
if (dst.remaining() < outputSize) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
392 |
return CoderResult.OVERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
393 |
// Put the byte in the output buffer |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
394 |
for (int i = 0; i < outputSize; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
395 |
dst.put(outputByte[i]); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
396 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
397 |
mark++; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
398 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
399 |
return CoderResult.UNDERFLOW; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
400 |
} finally { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
401 |
src.position(mark); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
402 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
403 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
404 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
405 |
protected CoderResult encodeLoop(CharBuffer src, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
406 |
ByteBuffer dst) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
407 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
408 |
if (src.hasArray() && dst.hasArray()) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
409 |
return encodeArrayLoop(src, dst); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
410 |
else |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
411 |
return encodeBufferLoop(src, dst); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
412 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
413 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
414 |
} |