summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Klute <klute@apache.org>2004-08-13 22:38:52 +0000
committerRainer Klute <klute@apache.org>2004-08-13 22:38:52 +0000
commita9b6743b20872b7cf519e2fd713ff57fcd3cf2eb (patch)
tree857547630272587c0c30cb77eb069dd2f863307d
parent626185e1225806454876c2ded7db42a50edc0764 (diff)
downloadpoi-a9b6743b20872b7cf519e2fd713ff57fcd3cf2eb.tar.gz
poi-a9b6743b20872b7cf519e2fd713ff57fcd3cf2eb.zip
Fixed a bug where a mutable section's format ID was written in the wrong byte order. Thanks to Bernd Freigang for pointing this out!
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353581 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/hpsf/ClassID.java16
-rw-r--r--src/java/org/apache/poi/hpsf/MutableSection.java8
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWrite.java18
3 files changed, 35 insertions, 7 deletions
diff --git a/src/java/org/apache/poi/hpsf/ClassID.java b/src/java/org/apache/poi/hpsf/ClassID.java
index 6d988637c4..0f8d12221b 100644
--- a/src/java/org/apache/poi/hpsf/ClassID.java
+++ b/src/java/org/apache/poi/hpsf/ClassID.java
@@ -96,6 +96,20 @@ public class ClassID
/**
+ * <p>Sets the bytes making out the class ID.</p>
+ *
+ * @param bytes The bytes making out the class ID in big-endian format. They
+ * are copied without their order being changed.
+ */
+ public void setBytes(final byte[] bytes)
+ {
+ for (int i = 0; i < this.bytes.length; i++)
+ this.bytes[i] = bytes[i];
+ }
+
+
+
+ /**
* <p>Reads the class ID's value from a byte array by turning
* little-endian into big-endian.</p>
*
@@ -134,7 +148,7 @@ public class ClassID
/**
* <p>Writes the class ID to a byte array in the
- * little-endian.</p>
+ * little-endian format.</p>
*
* @param dst The byte array to write to.
*
diff --git a/src/java/org/apache/poi/hpsf/MutableSection.java b/src/java/org/apache/poi/hpsf/MutableSection.java
index 9c47c71cbf..aef344aab2 100644
--- a/src/java/org/apache/poi/hpsf/MutableSection.java
+++ b/src/java/org/apache/poi/hpsf/MutableSection.java
@@ -127,7 +127,13 @@ public class MutableSection extends Section
*/
public void setFormatID(final byte[] formatID)
{
- setFormatID(new ClassID(formatID, 0));
+ ClassID fid = getFormatID();
+ if (fid == null)
+ {
+ fid = new ClassID();
+ setFormatID(fid);
+ }
+ fid.setBytes(formatID);
}
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
index defdaf0076..2113f6eb40 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
@@ -1,4 +1,3 @@
-
/* ====================================================================
Copyright 2002-2004 Apache Software Foundation
@@ -38,6 +37,7 @@ import java.util.Map;
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.apache.poi.hpsf.ClassID;
import org.apache.poi.hpsf.Constants;
import org.apache.poi.hpsf.HPSFRuntimeException;
import org.apache.poi.hpsf.IllegalPropertySetDataException;
@@ -259,6 +259,8 @@ public class TestWrite extends TestCase
SummaryInformation.DEFAULT_STREAM_NAME);
r.read(new FileInputStream(filename));
Assert.assertNotNull(psa[0]);
+ Assert.assertTrue(psa[0].isSummaryInformation());
+
final Section s = (Section) (psa[0].getSections().get(0));
Object p1 = s.getProperty(PropertyIDMap.PID_AUTHOR);
Object p2 = s.getProperty(PropertyIDMap.PID_TITLE);
@@ -293,9 +295,9 @@ public class TestWrite extends TestCase
final MutablePropertySet ps = new MutablePropertySet();
ps.clearSections();
- final byte[] formatID =
- new byte[]{0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15};
+ final ClassID formatID = new ClassID();
+ formatID.setBytes(new byte[]{0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15});
final MutableSection s1 = new MutableSection();
s1.setFormatID(formatID);
s1.setProperty(2, SECTION1);
@@ -336,6 +338,7 @@ public class TestWrite extends TestCase
r.read(new FileInputStream(filename));
Assert.assertNotNull(psa[0]);
Section s = (Section) (psa[0].getSections().get(0));
+ assertEquals(s.getFormatID(), formatID);
Object p = s.getProperty(2);
Assert.assertEquals(SECTION1, p);
s = (Section) (psa[0].getSections().get(1));
@@ -529,6 +532,7 @@ public class TestWrite extends TestCase
byte[] bytes = out.toByteArray();
PropertySet psr = new PropertySet(bytes);
+ assertTrue(psr.isSummaryInformation());
Section sr = (Section) psr.getSections().get(0);
String title = (String) sr.getProperty(PropertyIDMap.PID_TITLE);
assertEquals(TITLE, title);
@@ -709,7 +713,7 @@ public class TestWrite extends TestCase
/* Compare the property set stream with the corresponding one
* from the origin file and check whether they are equal. */
- assertEquals("Equality for file "+f.getName(),ps1, ps2);
+ assertEquals("Equality for file " + f.getName(), ps1, ps2);
}
}
catch (Exception ex)
@@ -755,6 +759,10 @@ public class TestWrite extends TestCase
final InputStream in = new ByteArrayInputStream(bytes);
final PropertySet ps2 = PropertySetFactory.create(in);
+ /* Check if the result is a DocumentSummaryInformation stream, as
+ * specified. */
+ assertTrue(ps2.isDocumentSummaryInformation());
+
/* Compare the property set stream with the corresponding one
* from the origin file and check whether they are equal. */
assertEquals(ps1, ps2);