ICUResourceBundleReader.java
3.53 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.ICUBinary;
import com.adobe.agl.impl.ICUData;
import com.adobe.agl.util.ULocale;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
public final class ICUResourceBundleReader
implements ICUBinary.Authenticate {
private static final byte[] DATA_FORMAT_ID = new byte[]{82, 101, 115, 66};
private byte[] dataVersion;
private int rootRes;
private int[] indexes;
private boolean noFallback;
private byte[] data;
private ICUResourceBundleReader(InputStream stream, String resolvedName) {
BufferedInputStream bs = new BufferedInputStream(stream);
try {
this.dataVersion = ICUBinary.readHeader(bs, DATA_FORMAT_ID, this);
this.readData(bs);
stream.close();
}
catch (IOException ex) {
throw new RuntimeException("Data file " + resolvedName + " is corrupt - " + ex.getMessage());
}
}
public static ICUResourceBundleReader getReader(String baseName, String localeName, ClassLoader root) {
String resolvedName = ICUResourceBundleReader.getFullName(baseName, localeName);
InputStream stream = ICUData.getStream(root, resolvedName);
if (stream == null) {
return null;
}
ICUResourceBundleReader reader = new ICUResourceBundleReader(stream, resolvedName);
return reader;
}
private static void writeInt(int i, byte[] bytes, int offset) {
bytes[offset++] = (byte)(i >> 24);
bytes[offset++] = (byte)(i >> 16);
bytes[offset++] = (byte)(i >> 8);
bytes[offset] = (byte)i;
}
private void readData(InputStream stream) throws IOException {
DataInputStream ds = new DataInputStream(stream);
this.rootRes = ds.readInt();
int indexLength = ds.readInt();
ds.mark((indexLength - 1) * 4);
this.indexes = new int[indexLength];
this.indexes[0] = indexLength;
for (int i = 1; i < indexLength; ++i) {
this.indexes[i] = ds.readInt();
}
this.noFallback = indexLength > 5 && (this.indexes[5] & 1) != 0;
int length = this.indexes[3] * 4;
this.data = new byte[length];
ICUResourceBundleReader.writeInt(this.rootRes, this.data, 0);
ICUResourceBundleReader.writeInt(indexLength, this.data, 4);
ds.reset();
ds.readFully(this.data, 8, length - 8);
}
public static String getFullName(String baseName, String localeName) {
if (baseName == null || baseName.length() == 0) {
if (localeName.length() == 0) {
return ULocale.getDefault().toString() + ".res";
}
return localeName + ".res";
}
if (baseName.indexOf(46) == -1) {
if (baseName.charAt(baseName.length() - 1) != '/') {
return baseName + "/" + localeName + ".res";
}
return baseName + localeName + ".res";
}
baseName = baseName.replace('.', '/');
if (localeName.length() == 0) {
return baseName + ".res";
}
return baseName + "_" + localeName + ".res";
}
public boolean isDataVersionAcceptable(byte[] version) {
return version[0] == 1 && version[1] >= 1;
}
public byte[] getData() {
return this.data;
}
public int getRootResource() {
return this.rootRes;
}
public boolean getNoFallback() {
return this.noFallback;
}
}