Lines 170-178
Link Here
|
170 |
* @param length The dictionary contains at most this many bytes. |
170 |
* @param length The dictionary contains at most this many bytes. |
171 |
* @param codepage The codepage of the string values. |
171 |
* @param codepage The codepage of the string values. |
172 |
* @return The dictonary |
172 |
* @return The dictonary |
|
|
173 |
* @exception UnsupportedEncodingException if the specified codepage is not |
174 |
* supported. |
173 |
*/ |
175 |
*/ |
174 |
protected Map readDictionary(final byte[] src, final long offset, |
176 |
protected Map readDictionary(final byte[] src, final long offset, |
175 |
final int length, final int codepage) |
177 |
final int length, final int codepage) |
|
|
178 |
throws UnsupportedEncodingException |
176 |
{ |
179 |
{ |
177 |
/* Check whether "offset" points into the "src" array". */ |
180 |
/* Check whether "offset" points into the "src" array". */ |
178 |
if (offset < 0 || offset > src.length) |
181 |
if (offset < 0 || offset > src.length) |
Lines 202-220
Link Here
|
202 |
long sLength = LittleEndian.getUInt(src, o); |
205 |
long sLength = LittleEndian.getUInt(src, o); |
203 |
o += LittleEndian.INT_SIZE; |
206 |
o += LittleEndian.INT_SIZE; |
204 |
/* Read the bytes or characters depending on whether the |
207 |
String value; |
205 |
* character set is Unicode or not. */ |
208 |
switch (codepage) |
206 |
StringBuffer b = new StringBuffer((int) sLength); |
209 |
{ |
207 |
for (int j = 0; j < sLength; j++) |
210 |
case -1: |
208 |
if (codepage == Constants.CP_UNICODE) |
211 |
value = new String(src, o, (int) sLength); |
209 |
{ |
212 |
break; |
210 |
final int i1 = o + (j * 2); |
213 |
case Constants.CP_UNICODE: |
211 |
final int i2 = i1 + 1; |
214 |
// In the case of UTF-16, the length represents the number of characters. |
212 |
b.append((char) ((src[i2] << 8) + src[i1])); |
215 |
value = new String(src, o, (int) sLength * 2, VariantSupport.codepageToEncoding(codepage)); |
213 |
} |
216 |
break; |
214 |
else |
217 |
default: |
215 |
b.append((char) src[o + j]); |
218 |
// TODO: Confirm the behaviour of UTF-8. |
216 |
|
219 |
value = new String(src, o, (int) sLength, VariantSupport.codepageToEncoding(codepage)); |
|
|
220 |
} |
221 |
|
222 |
StringBuffer b = new StringBuffer(value); |
223 |
|
217 |
/* Strip 0x00 characters from the end of the string: */ |
224 |
/* Strip 0x00 characters from the end of the string: */ |
218 |
while (b.length() > 0 && b.charAt(b.length() - 1) == 0x00) |
225 |
while (b.length() > 0 && b.charAt(b.length() - 1) == 0x00) |
219 |
b.setLength(b.length() - 1); |
226 |
b.setLength(b.length() - 1); |