mirror of https://github.com/apache/poi.git
try to fix tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903783 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a1cb1812dd
commit
ecfb35e0d9
|
@ -276,7 +276,7 @@ public class Ole10Native {
|
|||
byte[] buf = new byte[MAX_STRING_LENGTH];
|
||||
for (int i=0; i<buf.length; i++) {
|
||||
if ((buf[i] = is.readByte()) == 0) {
|
||||
return StringUtil.getFromCompressedUnicode(buf, 0, i);
|
||||
return StringUtil.getFromCompressedUTF8(buf, 0, i);
|
||||
}
|
||||
}
|
||||
throw new Ole10NativeException("AsciiZ string was not null terminated after " + MAX_STRING_LENGTH + " bytes - Exiting.");
|
||||
|
|
|
@ -48,7 +48,7 @@ public final class StringPtg extends ScalarConstantPtg {
|
|||
if (_is16bitUnicode) {
|
||||
field_3_string = StringUtil.readUnicodeLE(in, nChars);
|
||||
} else {
|
||||
field_3_string = StringUtil.readCompressedLatinA(in, nChars);
|
||||
field_3_string = StringUtil.readCompressedUnicode(in, nChars);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.poi.util;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -128,33 +129,40 @@ public final class StringUtil {
|
|||
* @param string byte array to read
|
||||
* @param offset offset to read byte array
|
||||
* @param len length to read byte array
|
||||
* @return String generated String instance by reading byte array
|
||||
* @return String generated String instance by reading byte array (ISO-8859-1)
|
||||
*/
|
||||
public static String getFromCompressedUnicode(
|
||||
final byte[] string,
|
||||
final int offset,
|
||||
final int len) {
|
||||
int len_to_use = Math.min(len, string.length - offset);
|
||||
return new String(string, offset, len_to_use, UTF8);
|
||||
return new String(string, offset, len_to_use, ISO_8859_1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read 8 bit data (in UTF-8 codepage) into a (unicode) Java
|
||||
* String and return.
|
||||
* (In Excel terms, read compressed 8 bit unicode as a string)
|
||||
*
|
||||
* @param string byte array to read
|
||||
* @param offset offset to read byte array
|
||||
* @param len length to read byte array
|
||||
* @return String generated String instance by reading byte array (UTF-8)
|
||||
*/
|
||||
public static String getFromCompressedUTF8(
|
||||
final byte[] string,
|
||||
final int offset,
|
||||
final int len) {
|
||||
int len_to_use = Math.min(len, string.length - offset);
|
||||
return new String(string, offset, len_to_use, UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param in stream,
|
||||
* @param nChars number pf chars
|
||||
* @return UTF-8 encoded result
|
||||
* @return ISO_8859_1 encoded result
|
||||
*/
|
||||
public static String readCompressedUnicode(LittleEndianInput in, int nChars) {
|
||||
byte[] buf = IOUtils.safelyAllocate(nChars, MAX_RECORD_LENGTH);
|
||||
in.readFully(buf);
|
||||
return new String(buf, UTF8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param in stream,
|
||||
* @param nChars number pf chars
|
||||
* @return LATIN-A (ISO-8859-1) encoded result
|
||||
*/
|
||||
public static String readCompressedLatinA(LittleEndianInput in, int nChars) {
|
||||
byte[] buf = IOUtils.safelyAllocate(nChars, MAX_RECORD_LENGTH);
|
||||
in.readFully(buf);
|
||||
return new String(buf, ISO_8859_1);
|
||||
|
|
Loading…
Reference in New Issue