diff options
author | Nick Burch <nick@apache.org> | 2016-07-20 23:31:57 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2016-07-20 23:31:57 +0000 |
commit | b25e988d943ea6ba523e927788f6f219a14570c3 (patch) | |
tree | 3976eebc8b1e6b6af98bb91676123af8c59345b6 /src/java/org/apache | |
parent | 2750df0433d1f90c163fadbaa8cd2d706cd19c48 (diff) | |
download | poi-b25e988d943ea6ba523e927788f6f219a14570c3.tar.gz poi-b25e988d943ea6ba523e927788f6f219a14570c3.zip |
If doing an in-place write, update the properties too
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753623 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/POIDocument.java | 14 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java | 3 | ||||
-rw-r--r-- | src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java index 80029e373d..06f101d3d6 100644 --- a/src/java/org/apache/poi/POIDocument.java +++ b/src/java/org/apache/poi/POIDocument.java @@ -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.SummaryInformation; 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 implements Closeable { 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) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 402b5d7e40..32789ca96d 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1311,6 +1311,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss 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(); } diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java index e1d4c5e5b5..e81888d06f 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java @@ -689,6 +689,8 @@ public class NPOIFSFileSystem extends BlockStore 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 |