diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java index 459e23ad3..bbd6c5e64 100644 --- a/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java +++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java @@ -90,10 +90,6 @@ public class Codec /** *

Converts a string into its hexadecimal notation.

- * - *

FIXME: If this method is called frequently, - * it should directly implement the algorithm in the called method - * in order to avoid creating a string instance.

*/ public static String hexEncode(final String s) { diff --git a/src/java/org/apache/poi/hpsf/SummaryInformation.java b/src/java/org/apache/poi/hpsf/SummaryInformation.java index 2b32f3fc3..0ad646e81 100644 --- a/src/java/org/apache/poi/hpsf/SummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/SummaryInformation.java @@ -310,12 +310,12 @@ public class SummaryInformation extends SpecialPropertySet * WMF or Clipboard (BMP?) format. He also provided two links that * might be helpful: http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch - * and http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch + * and http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp - * . However, we won't do any conversion into any image type - * but instead just return a byte array.

+ * target="_blank">http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp. + * However, we won't do any conversion into any image type but instead just + * return a byte array.

* * @return The thumbnail or null */ diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 29360420d..d85a588f3 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -230,7 +230,6 @@ public class VariantSupport extends Variant final int first = o1 + LittleEndian.INT_SIZE; long last = first + LittleEndian.getUInt(src, o1) - 1; o1 += LittleEndian.INT_SIZE; - final int rawLength = (int) (last - first + 1); while (src[(int) last] == 0 && first <= last) last--; final int l = (int) (last - first + 1); @@ -454,13 +453,6 @@ public class VariantSupport extends Variant } } - /* Add 0x00 characters to write a multiple of four bytes: */ - // FIXME (1) Try this! -// while (length % 4 != 0) -// { -// out.write(0); -// length++; -// } return length; } diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java index 95b78ea66..609f0358a 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java @@ -65,6 +65,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -402,7 +403,6 @@ public class TestWrite extends TestCase { Throwable t = null; final int codepage = -1; - /* FIXME (2): Add tests for various codepages! */ try { check(Variant.VT_EMPTY, null, codepage); @@ -414,8 +414,8 @@ public class TestWrite extends TestCase check(Variant.VT_CF, new byte[]{0, 1, 2, 3}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - codepage); + check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage); + check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage); check(Variant.VT_I2, new Integer(27), codepage); check(Variant.VT_I4, new Long(28), codepage); check(Variant.VT_FILETIME, new Date(), codepage); @@ -445,21 +445,80 @@ public class TestWrite extends TestCase t = ex; } if (t != null) + fail(org.apache.poi.hpsf.Util.toString(t)); + } + + + + /** + *

Writes and reads back strings using several different codepages and + * checks whether the stuff that has been read back equals the stuff that + * was written.

+ */ + public void testCodepages() + { + Throwable t = null; + final int[] validCodepages = new int[] {-1, 1252, 1200, 65001}; + for (int i = 0; i < validCodepages.length; i++) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - pw.close(); + int codepage = validCodepages[i]; try { - sw.close(); + check(Variant.VT_LPSTR, "", codepage); + check(Variant.VT_LPSTR, "ä", codepage); + check(Variant.VT_LPSTR, "äö", codepage); + check(Variant.VT_LPSTR, "äöü", codepage); + check(Variant.VT_LPSTR, "äöüÄ", codepage); + check(Variant.VT_LPSTR, "äöüÄÖ", codepage); + check(Variant.VT_LPSTR, "äöüÄÖÜ", codepage); + check(Variant.VT_LPSTR, "äöüÄÖÜß", codepage); + check(Variant.VT_LPSTR, "\u79D1\u5B78", codepage); } - catch (IOException ex2) + catch (Exception ex) { - t.printStackTrace(); + t = ex; } - fail(sw.toString()); + catch (Error ex) + { + t = ex; + } + if (t != null) + fail(org.apache.poi.hpsf.Util.toString(t)); } + + final int[] invalidCodepages = new int[] {0, 1, 2, 4711, 815}; + for (int i = 0; i < invalidCodepages.length; i++) + { + int codepage = invalidCodepages[i]; + try + { + check(Variant.VT_LPSTR, "", codepage); + check(Variant.VT_LPSTR, "ä", codepage); + check(Variant.VT_LPSTR, "äö", codepage); + check(Variant.VT_LPSTR, "äöü", codepage); + check(Variant.VT_LPSTR, "äöüÄ", codepage); + check(Variant.VT_LPSTR, "äöüÄÖ", codepage); + check(Variant.VT_LPSTR, "äöüÄÖÜ", codepage); + check(Variant.VT_LPSTR, "äöüÄÖÜß", codepage); + fail("UnsupportedEncodingException for codepage " + codepage + + " expected."); + } + catch (UnsupportedEncodingException ex) + { + /* This is the expected behaviour. */ + } + catch (Exception ex) + { + t = ex; + } + catch (Error ex) + { + t = ex; + } + if (t != null) + fail(org.apache.poi.hpsf.Util.toString(t)); + } + } @@ -482,11 +541,9 @@ public class TestWrite extends TestCase final byte[] b = out.toByteArray(); final Object objRead = VariantSupport.read(b, 0, b.length + LittleEndian.INT_SIZE, - variantType, -1); + variantType, codepage); if (objRead instanceof byte[]) { -// final int diff = diff(org.apache.poi.hpsf.Util.pad4 -// ((byte[]) value), (byte[]) objRead); final int diff = diff((byte[]) value, (byte[]) objRead); if (diff >= 0) fail("Byte arrays are different. First different byte is at " +