poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1753623 - in /poi/trunk/src/java/org/apache/poi: POIDocument.java hssf/usermodel/HSSFWorkbook.java poifs/filesystem/NPOIFSFileSystem.java
Date Wed, 20 Jul 2016 23:31:58 GMT
Author: nick
Date: Wed Jul 20 23:31:57 2016
New Revision: 1753623

URL: http://svn.apache.org/viewvc?rev=1753623&view=rev
Log:
If doing an in-place write, update the properties too

Modified:
    poi/trunk/src/java/org/apache/poi/POIDocument.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java

Modified: poi/trunk/src/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIDocument.java?rev=1753623&r1=1753622&r2=1753623&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Wed Jul 20 23:31:57 2016
@@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -34,6 +35,8 @@ import org.apache.poi.hpsf.SummaryInform
 import org.apache.poi.poifs.crypt.EncryptionInfo;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
+import org.apache.poi.poifs.filesystem.DocumentNode;
+import org.apache.poi.poifs.filesystem.NPOIFSDocument;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -298,7 +301,16 @@ public abstract class POIDocument implem
             mSet.write(bOut);
             byte[] data = bOut.toByteArray();
             ByteArrayInputStream bIn = new ByteArrayInputStream(data);
-            outFS.createDocument(bIn,name);
+            
+            // New or Existing?
+            // TODO Use a createOrUpdate method for this to be cleaner!
+            try {
+                DocumentNode propSetNode = (DocumentNode)outFS.getRoot().getEntry(name);
+                NPOIFSDocument propSetDoc = new NPOIFSDocument(propSetNode);
+                propSetDoc.replaceContents(bIn);
+            } catch (FileNotFoundException e) {
+                outFS.createDocument(bIn,name);
+            }
 
             logger.log(POILogger.INFO, "Wrote property set " + name + " of size " + data.length);
         } catch(org.apache.poi.hpsf.WritingNotSupportedException wnse) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1753623&r1=1753622&r2=1753623&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Wed Jul 20 23:31:57
2016
@@ -1311,6 +1311,9 @@ public final class HSSFWorkbook extends
         NPOIFSDocument workbookDoc = new NPOIFSDocument(workbookNode);
         workbookDoc.replaceContents(new ByteArrayInputStream(getBytes()));
         
+        // Update the properties streams in the file
+        writeProperties(directory.getFileSystem(), null);
+        
         // Sync with the File on disk
         directory.getFileSystem().writeFilesystem();
     }

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java?rev=1753623&r1=1753622&r2=1753623&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java Wed Jul 20 23:31:57
2016
@@ -689,6 +689,8 @@ public class NPOIFSFileSystem extends Bl
         return getRoot().createDocument(name, stream);
     }
 
+    // TODO Add a createOrUpdateDocument method to simplify code
+    
     /**
      * create a new DocumentEntry in the root entry; the data will be
      * provided later



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message