#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
This commit is contained in:
parent
492aac4e73
commit
b7b990f56f
@ -19,6 +19,7 @@ package org.apache.poi;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -45,7 +46,7 @@ import org.apache.poi.util.POILogger;
|
|||||||
* Document classes.
|
* Document classes.
|
||||||
* Currently, this relates to Document Information Properties
|
* Currently, this relates to Document Information Properties
|
||||||
*/
|
*/
|
||||||
public abstract class POIDocument {
|
public abstract class POIDocument implements Closeable {
|
||||||
/** Holds metadata on our document */
|
/** Holds metadata on our document */
|
||||||
private SummaryInformation sInf;
|
private SummaryInformation sInf;
|
||||||
/** Holds further metadata on our document */
|
/** Holds further metadata on our document */
|
||||||
@ -319,6 +320,22 @@ public abstract class POIDocument {
|
|||||||
*/
|
*/
|
||||||
public abstract void write(OutputStream out) throws IOException;
|
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
|
@Internal
|
||||||
public DirectoryNode getDirectory() {
|
public DirectoryNode getDirectory() {
|
||||||
return directory;
|
return directory;
|
||||||
|
@ -1276,16 +1276,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
* Closes the underlying {@link NPOIFSFileSystem} from which
|
* Closes the underlying {@link NPOIFSFileSystem} from which
|
||||||
* the Workbook was read, if any. Has no effect on Workbooks
|
* the Workbook was read, if any. Has no effect on Workbooks
|
||||||
* opened from an InputStream, or newly created ones.
|
* 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
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException {
|
||||||
{
|
super.close();
|
||||||
if (directory != null) {
|
|
||||||
if (directory.getNFileSystem() != null) {
|
|
||||||
directory.getNFileSystem().close();
|
|
||||||
directory = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user