==================================================================== */
package org.apache.poi;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.util.IOUtils;
import org.apache.xmlbeans.impl.common.SystemCache;
-public abstract class POIXMLDocument extends POIXMLDocumentPart{
+public abstract class POIXMLDocument extends POIXMLDocumentPart implements Closeable {
public static final String DOCUMENT_CREATOR = "Apache POI";
// OLE embeddings relation name
* Closes the underlying {@link OPCPackage} from which this
* document was read, if there is one
*/
- protected void close() throws IOException {
+ public void close() throws IOException {
if (pkg != null) {
if (pkg.getPackageAccess() == PackageAccess.READ) {
pkg.revert();
out.close();
}
- /**
- * Closes the underlying {@link OPCPackage} from which
- * the Workbook was read, if any. Has no effect on newly
- * created Workbooks.
- */
- @Override
- public void close() throws IOException {
- super.close();
- }
-
/**
* Returns SharedStringsTable - tha cache of string for this workbook
*
public void testRelationOrder() throws Exception {
OPCPackage pkg = PackageHelper.open(POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx"));
OPCParser doc = new OPCParser(pkg);
- doc.parse(new TestFactory());
-
- for(POIXMLDocumentPart rel : doc.getRelations()){
- //TODO finish me
- assertNotNull(rel);
+ try {
+ doc.parse(new TestFactory());
+
+ for(POIXMLDocumentPart rel : doc.getRelations()){
+ //TODO finish me
+ assertNotNull(rel);
+ }
+ } finally {
+ doc.close();
}
-
}
public void testCommitNullPart() throws IOException, InvalidFormatException {