UConverterDataReader.java
5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.charset;
import com.adobe.agl.charset.CharsetMBCS;
import com.adobe.agl.charset.UConverterStaticData;
import com.adobe.agl.impl.ICUBinary;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
final class UConverterDataReader
implements ICUBinary.Authenticate {
int bytesRead = 0;
int staticDataBytesRead = 0;
DataInputStream dataInputStream;
private static final byte[] DATA_FORMAT_ID = new byte[]{99, 110, 118, 116};
private static final byte[] DATA_FORMAT_VERSION = new byte[]{6};
protected UConverterDataReader(InputStream inputStream) throws IOException {
ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);
this.dataInputStream = new DataInputStream(inputStream);
}
protected void readStaticData(UConverterStaticData sd) throws IOException {
int bRead = 0;
sd.structSize = this.dataInputStream.readInt();
bRead += 4;
byte[] name = new byte[60];
this.dataInputStream.readFully(name);
bRead += name.length;
sd.name = new String(name, 0, name.length);
sd.codepage = this.dataInputStream.readInt();
bRead += 4;
sd.platform = this.dataInputStream.readByte();
++bRead;
sd.conversionType = this.dataInputStream.readByte();
++bRead;
sd.minBytesPerChar = this.dataInputStream.readByte();
++bRead;
sd.maxBytesPerChar = this.dataInputStream.readByte();
++bRead;
this.dataInputStream.readFully(sd.subChar);
bRead += sd.subChar.length;
sd.subCharLen = this.dataInputStream.readByte();
++bRead;
sd.hasToUnicodeFallback = this.dataInputStream.readByte();
++bRead;
sd.hasFromUnicodeFallback = this.dataInputStream.readByte();
++bRead;
sd.unicodeMask = (short)this.dataInputStream.readUnsignedByte();
++bRead;
sd.subChar1 = this.dataInputStream.readByte();
++bRead;
this.dataInputStream.readFully(sd.reserved);
this.staticDataBytesRead = bRead += sd.reserved.length;
this.bytesRead += bRead;
}
protected void readMBCSHeader(CharsetMBCS.MBCSHeader h) throws IOException {
this.dataInputStream.readFully(h.version);
this.bytesRead += h.version.length;
h.countStates = this.dataInputStream.readInt();
this.bytesRead += 4;
h.countToUFallbacks = this.dataInputStream.readInt();
this.bytesRead += 4;
h.offsetToUCodeUnits = this.dataInputStream.readInt();
this.bytesRead += 4;
h.offsetFromUTable = this.dataInputStream.readInt();
this.bytesRead += 4;
h.offsetFromUBytes = this.dataInputStream.readInt();
this.bytesRead += 4;
h.flags = this.dataInputStream.readInt();
this.bytesRead += 4;
h.fromUBytesLength = this.dataInputStream.readInt();
this.bytesRead += 4;
if (h.version[0] == 5 && h.version[1] >= 3) {
h.options = this.dataInputStream.readInt();
this.bytesRead += 4;
if ((h.options & 64) != 0) {
h.fullStage2Length = this.dataInputStream.readInt();
this.bytesRead += 4;
}
}
}
protected void readMBCSTable(int[][] stateTableArray, CharsetMBCS.MBCSToUFallback[] toUFallbacksArray, char[] unicodeCodeUnitsArray, char[] fromUnicodeTableArray, byte[] fromUnicodeBytesArray) throws IOException {
int i;
for (i = 0; i < stateTableArray.length; ++i) {
for (int j = 0; j < stateTableArray[i].length; ++j) {
stateTableArray[i][j] = this.dataInputStream.readInt();
this.bytesRead += 4;
}
}
for (i = 0; i < toUFallbacksArray.length; ++i) {
toUFallbacksArray[i].offset = this.dataInputStream.readInt();
this.bytesRead += 4;
toUFallbacksArray[i].codePoint = this.dataInputStream.readInt();
this.bytesRead += 4;
}
for (i = 0; i < unicodeCodeUnitsArray.length; ++i) {
unicodeCodeUnitsArray[i] = this.dataInputStream.readChar();
this.bytesRead += 2;
}
for (i = 0; i < fromUnicodeTableArray.length; ++i) {
fromUnicodeTableArray[i] = this.dataInputStream.readChar();
this.bytesRead += 2;
}
for (i = 0; i < fromUnicodeBytesArray.length; ++i) {
fromUnicodeBytesArray[i] = this.dataInputStream.readByte();
++this.bytesRead;
}
}
protected String readBaseTableName() throws IOException {
char c;
StringBuffer name = new StringBuffer();
while ((c = (char)this.dataInputStream.readByte()) != '\u0000') {
name.append(c);
++this.bytesRead;
}
++this.bytesRead;
return name.toString();
}
protected ByteBuffer readExtIndexes(int skip) throws IOException {
int skipped = this.dataInputStream.skipBytes(skip);
if (skipped != skip) {
throw new IOException("could not skip " + skip + " bytes");
}
int n = this.dataInputStream.readInt();
this.bytesRead += 4;
int[] indexes = new int[n];
indexes[0] = n;
for (int i = 1; i < n; ++i) {
indexes[i] = this.dataInputStream.readInt();
this.bytesRead += 4;
}
ByteBuffer b = ByteBuffer.allocate(indexes[31]);
for (int i2 = 0; i2 < n; ++i2) {
b.putInt(indexes[i2]);
}
int len = this.dataInputStream.read(b.array(), b.position(), b.remaining());
if (len == -1) {
throw new IOException("Read failed");
}
this.bytesRead += len;
return b;
}
byte[] getDataFormatVersion() {
return DATA_FORMAT_VERSION;
}
public boolean isDataVersionAcceptable(byte[] version) {
return version[0] == DATA_FORMAT_VERSION[0];
}
}