aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2016-07-20 22:35:51 +0000
committerNick Burch <nick@apache.org>2016-07-20 22:35:51 +0000
commitefb790ef95dae3835018619518508736f4b15785 (patch)
tree8b5995e08311a2120152d167cae2065959e1863d /src/java/org/apache
parent667cfcb196f7cbad1771d1f7b5295a4529f54569 (diff)
downloadpoi-efb790ef95dae3835018619518508736f4b15785.tar.gz
poi-efb790ef95dae3835018619518508736f4b15785.zip
#57919 Add in-place and new-File write methods to POIDocument
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753619 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/poi/POIDocument.java4
-rw-r--r--src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java30
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java4
3 files changed, 30 insertions, 8 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java
index 10862c6c4b..80029e373d 100644
--- a/src/java/org/apache/poi/POIDocument.java
+++ b/src/java/org/apache/poi/POIDocument.java
@@ -338,7 +338,7 @@ public abstract class POIDocument implements Closeable {
*
* @throws IOException thrown on errors writing to the file
*/
- //public abstract void write() throws IOException; // TODO Implement elsewhere
+ public abstract void write() throws IOException;
/**
* Writes the document out to the specified new {@link File}. If the file
@@ -348,7 +348,7 @@ public abstract class POIDocument implements Closeable {
*
* @throws IOException thrown on errors writing to the file
*/
- //public abstract void write(File newFile) throws IOException; // TODO Implement elsewhere
+ public abstract void write(File newFile) throws IOException;
/**
* Writes the document out to the specified output stream. The
diff --git a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
index 9b0f84d470..2e6656acde 100644
--- a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
+++ b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
@@ -16,6 +16,7 @@
==================================================================== */
package org.apache.poi.hpsf;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -45,13 +46,35 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
}
/**
+ * Write out to the currently open file the properties changes, but nothing else
+ */
+ public void write() throws IOException {
+ NPOIFSFileSystem fs = directory.getFileSystem();
+
+ validateInPlaceWritePossible();
+ writeProperties(fs, null);
+ fs.writeFilesystem();
+ }
+ /**
+ * Write out, with any properties changes, but nothing else
+ */
+ public void write(File newFile) throws IOException {
+ POIFSFileSystem fs = POIFSFileSystem.create(newFile);
+ write(fs);
+ fs.writeFilesystem();
+ }
+ /**
* Write out, with any properties changes, but nothing else
*/
public void write(OutputStream out) throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
-
+ write(fs);
+ fs.writeFilesystem(out);
+ }
+
+ private void write(NPOIFSFileSystem fs) throws IOException {
// For tracking what we've written out, so far
- List<String> excepts = new ArrayList<String>(1);
+ List<String> excepts = new ArrayList<String>(2);
// Write out our HPFS properties, with any changes
writeProperties(fs, excepts);
@@ -59,7 +82,6 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
// Copy over everything else unchanged
EntryUtils.copyNodes(directory, fs.getRoot(), excepts);
- // Save the resultant POIFSFileSystem to the output stream
- fs.writeFilesystem(out);
+ // Caller will save the resultant POIFSFileSystem to the stream/file
}
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index b7d3ff0a0f..402b5d7e40 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -1301,7 +1301,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* you must use {@link #write(OutputStream)} or {@link #write(File)} to
* write to a brand new document.
*/
- //@Override // TODO Not yet on POIDocument
+ @Override
public void write() throws IOException {
validateInPlaceWritePossible();
@@ -1330,7 +1330,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @exception IOException if anything can't be written.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
*/
- //@Override // TODO Not yet on POIDocument
+ @Override
public void write(File newFile) throws IOException {
POIFSFileSystem fs = POIFSFileSystem.create(newFile);
try {