]> source.dussan.org Git - poi.git/commitdiff
Add a write method to HPSFPropertiesOnlyDocument, and use this to finish the unit...
authorNick Burch <nick@apache.org>
Wed, 26 Jun 2013 00:18:41 +0000 (00:18 +0000)
committerNick Burch <nick@apache.org>
Wed, 26 Jun 2013 00:18:41 +0000 (00:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1496683 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java

index 196cabbbb52cfe542f4ac414260e2f05f10c4ef9..7e341a896da2636795ea8f37b12a7a3ab760f241 100644 (file)
@@ -1,8 +1,12 @@
 package org.apache.poi.hpsf;
 
+import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.poi.POIDocument;
+import org.apache.poi.poifs.filesystem.EntryUtils;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
@@ -20,7 +24,22 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
         super(fs);
     }
 
-    public void write(OutputStream out) {
-        throw new IllegalStateException("Unable to write, only for properties!");
+    /**
+     * Write out, with any properties changes, but nothing else
+     */
+    public void write(OutputStream out) throws IOException {
+        POIFSFileSystem fs = new POIFSFileSystem();
+
+        // For tracking what we've written out, so far
+        List<String> excepts = new ArrayList<String>(1);
+
+        // Write out our HPFS properties, with any changes
+        writeProperties(fs, excepts);
+        
+        // Copy over everything else unchanged
+        EntryUtils.copyNodes(directory, fs.getRoot(), excepts);
+        
+        // Save the resultant POIFSFileSystem to the output stream
+        fs.writeFilesystem(out);
     }
 }
\ No newline at end of file
index c27b369c80d554f79a75240e880f4ece9b651c75..05c8d8b99fc2aeff4ca9d500ece2f375cf9aaa86 100644 (file)
@@ -24,7 +24,9 @@ import java.util.Date;
 import junit.framework.TestCase;
 
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.POIDocument;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
+import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -124,6 +126,16 @@ public final class TestHPSFBugs extends TestCase {
        
        
        // Write out and read back, should still be valid
-       // TODO
+       POIDocument doc = new HPSFPropertiesOnlyDocument(fs);
+       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+       doc.write(baos);
+       ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+       doc = new HPSFPropertiesOnlyDocument(new POIFSFileSystem(bais));
+       
+       // Check properties are still there
+       assertEquals("Microsoft Word 10.0", si.getApplicationName());
+       assertEquals("", si.getTitle());
+       assertEquals("", si.getAuthor());
+       assertEquals("Cour de Justice", dsi.getCompany());
    }
 }