diff options
author | Nick Burch <nick@apache.org> | 2016-07-21 23:09:07 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2016-07-21 23:09:07 +0000 |
commit | 6d59eef6e47f6266b3f64d2a90c9cbe153b8cb90 (patch) | |
tree | 193963e0248bb5cbba10c18a377593cbc757f366 /src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java | |
parent | 48f255f37e272fa4f131d534753af21159432420 (diff) | |
download | poi-6d59eef6e47f6266b3f64d2a90c9cbe153b8cb90.tar.gz poi-6d59eef6e47f6266b3f64d2a90c9cbe153b8cb90.zip |
Provide a createOrUpdateDocument method at the POIFS level, and use to simplify writing code #57919
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753739 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java')
-rw-r--r-- | src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java b/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java index 9be71a5ccf..ccb008507b 100644 --- a/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java +++ b/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java @@ -479,6 +479,38 @@ public class DirectoryNode } /** + * Set the contents of a document, creating if needed, + * otherwise updating. Returns the created / updated DocumentEntry + * + * @param name the name of the new or existing DocumentEntry + * @param stream the InputStream from which to populate the DocumentEntry + * + * @return the new or updated DocumentEntry + * + * @exception IOException + */ + + public DocumentEntry createOrUpdateDocument(final String name, + final InputStream stream) + throws IOException + { + if (! hasEntry(name)) { + return createDocument(name, stream); + } else { + DocumentNode existing = (DocumentNode)getEntry(name); + if (_nfilesystem != null) { + NPOIFSDocument nDoc = new NPOIFSDocument(existing); + nDoc.replaceContents(stream); + return existing; + } else { + // Do it the hard way for Old POIFS... + deleteEntry(existing); + return createDocument(name, stream); + } + } + } + + /** * Gets the storage clsid of the directory entry * * @return storage Class ID |