think I may have fixed the encoding thing... maybe..... I hope..

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352907 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-11-08 02:34:08 +00:00
parent ab23eab68d
commit b8f9260d23
3 changed files with 25 additions and 3 deletions

View File

@ -55,6 +55,8 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.io.UnsupportedEncodingException;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
@ -153,7 +155,12 @@ public class UnicodeString
field_2_optionflags = data[ 2 ]; field_2_optionflags = data[ 2 ];
if ((field_2_optionflags & 1) == 0) if ((field_2_optionflags & 1) == 0)
{ {
field_3_string = new String(data, 3, getCharCount()); try {
field_3_string = new String(data, 3, getCharCount(),
StringUtil.getPreferredEncoding());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} }
else else
{ {

View File

@ -75,6 +75,8 @@ import java.text.FieldPosition;
*/ */
public class StringUtil { public class StringUtil {
private final static String ENCODING="ISO-8859-1";
/** /**
* Constructor for the StringUtil object * Constructor for the StringUtil object
*/ */
@ -105,6 +107,7 @@ public class StringUtil {
public static String getFromUnicodeHigh(final byte[] string, public static String getFromUnicodeHigh(final byte[] string,
final int offset, final int len) final int offset, final int len)
throws ArrayIndexOutOfBoundsException, IllegalArgumentException { throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
if ((offset < 0) || (offset >= string.length)) { if ((offset < 0) || (offset >= string.length)) {
throw new ArrayIndexOutOfBoundsException("Illegal offset"); throw new ArrayIndexOutOfBoundsException("Illegal offset");
} }
@ -331,4 +334,8 @@ public class StringUtil {
numberFormat.format(number, outputTo, new FieldPosition(0)); numberFormat.format(number, outputTo, new FieldPosition(0));
return 1; return 1;
} }
public static String getPreferredEncoding() {
return ENCODING;
}
} }

View File

@ -206,7 +206,7 @@ public class TestStringUtil
* Test putCompressedUnicode * Test putCompressedUnicode
*/ */
public void testPutCompressedUnicode() public void testPutCompressedUnicode() throws Exception
{ {
byte[] output = new byte[ 100 ]; byte[] output = new byte[ 100 ];
byte[] expected_output = byte[] expected_output =
@ -215,7 +215,7 @@ public class TestStringUtil
( byte ) 'o', ( byte ) ' ', ( byte ) 'W', ( byte ) 'o', ( byte ) 'o', ( byte ) ' ', ( byte ) 'W', ( byte ) 'o',
( byte ) 'r', ( byte ) 'l', ( byte ) 'd', ( byte ) 0xAE ( byte ) 'r', ( byte ) 'l', ( byte ) 'd', ( byte ) 0xAE
}; };
String input = new String(expected_output); String input = new String(expected_output,StringUtil.getPreferredEncoding());
StringUtil.putCompressedUnicode(input, output, 0); StringUtil.putCompressedUnicode(input, output, 0);
for (int j = 0; j < expected_output.length; j++) for (int j = 0; j < expected_output.length; j++)
@ -355,4 +355,12 @@ public class TestStringUtil
System.out.println("Testing util.StringUtil functionality"); System.out.println("Testing util.StringUtil functionality");
junit.textui.TestRunner.run(TestStringUtil.class); junit.textui.TestRunner.run(TestStringUtil.class);
} }
/**
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
// System.setProperty()
}
} }