]> source.dussan.org Git - poi.git/commitdiff
#57919 HPSF writing better error handling, and start prep for HSLF more write methods
authorNick Burch <nick@apache.org>
Wed, 20 Jul 2016 23:09:33 +0000 (23:09 +0000)
committerNick Burch <nick@apache.org>
Wed, 20 Jul 2016 23:09:33 +0000 (23:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753621 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java

index 2e6656acde789b21fdc4c3affd7ba5de86f7bd04..78ee5512b711dd8d40e1a79ecde925ed49e10fc7 100644 (file)
@@ -60,16 +60,24 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
      */
     public void write(File newFile) throws IOException {
         POIFSFileSystem fs = POIFSFileSystem.create(newFile);
-        write(fs);
-        fs.writeFilesystem();
+        try {
+            write(fs);
+            fs.writeFilesystem();
+        } finally {
+            fs.close();
+        }
     }
     /**
      * 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);
+        try {
+            write(fs);
+            fs.writeFilesystem(out);
+        } finally {
+            fs.close();
+        }
     }
     
     private void write(NPOIFSFileSystem fs) throws IOException {
index 012af2b584e19219bd259dd1299907d807ed9fc8..223e6036e4fb6b123ac60ec844bda745da571ed9 100644 (file)
@@ -564,7 +564,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
        @Override
     public void write(OutputStream out) throws IOException {
         // Write out, but only the common streams
-        write(out,false);
+        write(out, false);
     }
     /**
      * Writes out the slideshow file the is represented by an instance
@@ -577,8 +577,22 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
      *           the passed in OutputStream
      */
     public void write(OutputStream out, boolean preserveNodes) throws IOException {
+        // Get a new FileSystem to write into
+        POIFSFileSystem outFS = new POIFSFileSystem();
+        
+        try {
+            // Write into the new FileSystem
+            write(outFS, preserveNodes);
+
+            // Send the POIFSFileSystem object out to the underlying stream
+            outFS.writeFilesystem(out);
+        } finally {
+            outFS.close();
+        }
+    }
+    private void write(POIFSFileSystem outFS, boolean preserveNodes) throws IOException {
         // read properties and pictures, with old encryption settings where appropriate 
-        if(_pictures == null) {
+        if (_pictures == null) {
            readPictures();
         }
         getDocumentSummaryInformation();
@@ -587,9 +601,6 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
         HSLFSlideShowEncrypted encryptedSS = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
         _records = encryptedSS.updateEncryptionRecord(_records);
 
-        // Get a new Filesystem to write into
-        POIFSFileSystem outFS = new POIFSFileSystem();
-
         // The list of entries we've written out
         List<String> writtenEntries = new ArrayList<String>(1);
 
@@ -633,13 +644,9 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
         }
 
         // If requested, write out any other streams we spot
-        if(preserveNodes) {
+        if (preserveNodes) {
             EntryUtils.copyNodes(directory.getFileSystem(), outFS, writtenEntries);
         }
-
-        // Send the POIFSFileSystem object out to the underlying stream
-        outFS.writeFilesystem(out);
-        outFS.close();
     }
 
     /**