You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2016/06/19 22:12:55 UTC

svn commit: r1749213 - in /poi/trunk/src/java/org/apache/poi: POIDocument.java hssf/usermodel/HSSFWorkbook.java

Author: nick
Date: Sun Jun 19 22:12:55 2016
New Revision: 1749213

URL: http://svn.apache.org/viewvc?rev=1749213&view=rev
Log:
#59724 Provide Closeable on all OLE2-based POIDocument types

Modified:
    poi/trunk/src/java/org/apache/poi/POIDocument.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java

Modified: poi/trunk/src/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIDocument.java?rev=1749213&r1=1749212&r2=1749213&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Sun Jun 19 22:12:55 2016
@@ -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;

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1749213&r1=1749212&r2=1749213&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Sun Jun 19 22:12:55 2016
@@ -1276,16 +1276,13 @@ public final class HSSFWorkbook extends
      * 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();
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org