diff options
author | Javen O'Neal <onealj@apache.org> | 2017-06-20 08:13:58 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2017-06-20 08:13:58 +0000 |
commit | 8358a80a1420e25654eb31e311b419cb7e8eb5dd (patch) | |
tree | 09a099502be3cf86a9c48702a55d3720d45122aa /src/java/org/apache/poi | |
parent | b761cbb7b94a6f93e6d08255150678c955437300 (diff) | |
download | poi-8358a80a1420e25654eb31e311b419cb7e8eb5dd.tar.gz poi-8358a80a1420e25654eb31e311b419cb7e8eb5dd.zip |
bug 57919: close opened resources
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1799316 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r-- | src/java/org/apache/poi/util/IOUtils.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/util/IOUtils.java b/src/java/org/apache/poi/util/IOUtils.java index 1f4429f58f..3af010b7b5 100644 --- a/src/java/org/apache/poi/util/IOUtils.java +++ b/src/java/org/apache/poi/util/IOUtils.java @@ -31,6 +31,7 @@ import java.util.zip.Checksum; import org.apache.poi.EmptyFileException; import org.apache.poi.POIDocument; +import org.apache.poi.ss.usermodel.Workbook; public final class IOUtils { private static final POILogger logger = POILogFactory.getLogger( IOUtils.class ); @@ -209,6 +210,14 @@ public final class IOUtils { } } + public static void write(Workbook doc, OutputStream out) throws IOException { + try { + doc.write(out); + } finally { + closeQuietly(out); + } + } + /** * Write a POI Document ({@link org.apache.poi.ss.usermodel.Workbook}, {@link org.apache.poi.sl.usermodel.SlideShow}, etc) to an output stream and close the output stream. * This will attempt to close the output stream at the end even if there was a problem writing the document to the stream. @@ -265,6 +274,16 @@ public final class IOUtils { closeQuietly(doc); } } + + // Since the Workbook interface doesn't derive from POIDocument + // We'll likely need one of these for each document container interface + public static void writeAndClose(Workbook doc, OutputStream out) throws IOException { + try { + doc.write(out); + } finally { + closeQuietly(doc); + } + } /** * Copies all the data from the given InputStream to the OutputStream. It |