From 2d44399e0b3ee5a3b16ac2b0ae8bcb63c1cbfcb8 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 20 Jul 2016 23:09:33 +0000 Subject: [PATCH] #57919 HPSF writing better error handling, and start prep for HSLF more write methods git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753621 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hpsf/HPSFPropertiesOnlyDocument.java | 16 ++++++++--- .../poi/hslf/usermodel/HSLFSlideShowImpl.java | 27 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java index 2e6656acde..78ee5512b7 100644 --- a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java +++ b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java @@ -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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java index 012af2b584..223e6036e4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java @@ -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 writtenEntries = new ArrayList(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(); } /** -- 2.39.5