aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2016-06-19 22:12:55 +0000
committerNick Burch <nick@apache.org>2016-06-19 22:12:55 +0000
commitfb80ba4949e9acb8f8370f2fce72d50377aa37d7 (patch)
treef3ee2d0df44b07903a30546706f7cc973fb13091 /src/java/org/apache/poi
parenta15ca7acfcc22aa52c5f2112ff37d9eeb3b1d7ca (diff)
downloadpoi-fb80ba4949e9acb8f8370f2fce72d50377aa37d7.tar.gz
poi-fb80ba4949e9acb8f8370f2fce72d50377aa37d7.zip
#59724 Provide Closeable on all OLE2-based POIDocument types
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749213 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/POIDocument.java19
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java13
2 files changed, 23 insertions, 9 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java
index 68ed3c1769..27a3ca648d 100644
--- a/src/java/org/apache/poi/POIDocument.java
+++ b/src/java/org/apache/poi/POIDocument.java
@@ -19,6 +19,7 @@ package org.apache.poi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -45,7 +46,7 @@ import org.apache.poi.util.POILogger;
* Document classes.
* Currently, this relates to Document Information Properties
*/
-public abstract class POIDocument {
+public abstract class POIDocument implements Closeable {
/** Holds metadata on our document */
private SummaryInformation sInf;
/** Holds further metadata on our document */
@@ -319,6 +320,22 @@ public abstract class POIDocument {
*/
public abstract void write(OutputStream out) throws IOException;
+ /**
+ * Closes the underlying {@link NPOIFSFileSystem} from which
+ * the document was read, if any. Has no effect on documents
+ * opened from an InputStream, or newly created ones.
+ * <p>Once {@link #close()} has been called, no further operations
+ * should be called on the document.
+ */
+ public void close() throws IOException {
+ if (directory != null) {
+ if (directory.getNFileSystem() != null) {
+ directory.getNFileSystem().close();
+ directory = null;
+ }
+ }
+ }
+
@Internal
public DirectoryNode getDirectory() {
return directory;
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index 4b041ef17a..d35aa4b571 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -1276,16 +1276,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Closes the underlying {@link NPOIFSFileSystem} from which
* the Workbook was read, if any. Has no effect on Workbooks
* opened from an InputStream, or newly created ones.
+ * <p>Once {@link #close()} has been called, no further
+ * operations, updates or reads should be performed on the
+ * Workbook.
*/
@Override
- public void close() throws IOException
- {
- if (directory != null) {
- if (directory.getNFileSystem() != null) {
- directory.getNFileSystem().close();
- directory = null;
- }
- }
+ public void close() throws IOException {
+ super.close();
}
/**