try to fix tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903783 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
index 681f4bd..0a8d8e9 100644
--- a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
+++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
@@ -276,7 +276,7 @@
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.");
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/ptg/StringPtg.java b/poi/src/main/java/org/apache/poi/ss/formula/ptg/StringPtg.java
index 1439cd8..bb58685 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/ptg/StringPtg.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/ptg/StringPtg.java
@@ -48,7 +48,7 @@
if (_is16bitUnicode) {
field_3_string = StringUtil.readUnicodeLE(in, nChars);
} else {
- field_3_string = StringUtil.readCompressedLatinA(in, nChars);
+ field_3_string = StringUtil.readCompressedUnicode(in, nChars);
}
}
diff --git a/poi/src/main/java/org/apache/poi/util/StringUtil.java b/poi/src/main/java/org/apache/poi/util/StringUtil.java
index 8cb1d51..c1bb521 100644
--- a/poi/src/main/java/org/apache/poi/util/StringUtil.java
+++ b/poi/src/main/java/org/apache/poi/util/StringUtil.java
@@ -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,35 +129,42 @@
* @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);
}