47179 - Fix string encoding issues with HSMF chunks on non-windows platforms

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@775508 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2009-05-16 19:12:30 +00:00
parent 19a885a5d7
commit 10d3184567
4 changed files with 23 additions and 4 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="fix">47179 - Fix string encoding issues with HSMF chunks on non-windows platforms</action>
<action dev="POI-DEVELOPERS" type="add">47183 - Attachment support for HSMF</action>
<action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
<action dev="POI-DEVELOPERS" type="fix">47048 - Fixed evaluation of defined names with the 'complex' flag set</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="fix">47179 - Fix string encoding issues with HSMF chunks on non-windows platforms</action>
<action dev="POI-DEVELOPERS" type="add">47183 - Attachment support for HSMF</action>
<action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
<action dev="POI-DEVELOPERS" type="fix">47048 - Fixed evaluation of defined names with the 'complex' flag set</action>

View File

@ -18,6 +18,9 @@
package org.apache.poi.hsmf.datatypes;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import org.apache.poi.hsmf.datatypes.Types;
/**
* A Chunk made up of a single string.
@ -61,7 +64,21 @@ public class StringChunk extends Chunk {
* @see org.apache.poi.hsmf.Chunk.Chunk#setValue(java.io.ByteArrayOutputStream)
*/
public void setValue(ByteArrayOutputStream value) {
this.value = value.toString().replaceAll("\0", "");
String tmpValue;
if (type == Types.NEW_STRING) {
try {
tmpValue = new String(value.toByteArray(), "UTF-16LE");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Core encoding not found, JVM broken?", e);
}
} else {
try {
tmpValue = new String(value.toByteArray(), "CP1252");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Core encoding not found, JVM broken?", e);
}
}
this.value = tmpValue.replace("\0", "");
}
public String toString() {

View File

@ -68,7 +68,7 @@ public class TestBlankFileRead extends TestCase {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
TestCase.assertEquals(obtained, expected);
TestCase.assertEquals(expected, obtained);
}
/**
@ -80,7 +80,7 @@ public class TestBlankFileRead extends TestCase {
String obtained = mapiMessage.getDisplayTo();
String expected = "";
TestCase.assertEquals(obtained, expected);
TestCase.assertEquals(expected, obtained);
}
/**
@ -107,7 +107,7 @@ public class TestBlankFileRead extends TestCase {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
TestCase.assertEquals(obtained, expected);
TestCase.assertEquals(expected, obtained);
}