]> source.dussan.org Git - poi.git/commitdiff
close input streams for parts
authorPJ Fanning <fanningpj@apache.org>
Tue, 28 Dec 2021 02:33:44 +0000 (02:33 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 28 Dec 2021 02:33:44 +0000 (02:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896462 13f79535-47bb-0310-9956-ffa450edef68

25 files changed:
poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLProperties.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java
poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFCommentAuthors.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFComments.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTheme.java
poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java

index 7ccbe771d717f31825e906c04f61608830f8c880..daa68d017bf287759aad7fec2ac9dd84883835b8 100644 (file)
@@ -78,9 +78,11 @@ public class POIXMLProperties {
             if (extPart == null) {
                 ext = new ExtendedProperties((org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument)NEW_EXT_INSTANCE.copy());
             } else {
-                org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse(
-                        extPart.getInputStream(), DEFAULT_XML_OPTIONS);
-                ext = new ExtendedProperties(props);
+                try (InputStream stream = extPart.getInputStream()) {
+                    org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse(
+                            stream, DEFAULT_XML_OPTIONS);
+                    ext = new ExtendedProperties(props);
+                }
             }
         } else {
             extPart = null;
@@ -95,9 +97,11 @@ public class POIXMLProperties {
             if (custPart == null) {
                 cust = new CustomProperties((org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument)NEW_CUST_INSTANCE.copy());
             } else {
-                org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse(
-                        custPart.getInputStream(), DEFAULT_XML_OPTIONS);
-                cust = new CustomProperties(props);
+                try (InputStream stream = custPart.getInputStream()) {
+                    org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse(
+                            stream, DEFAULT_XML_OPTIONS);
+                    cust = new CustomProperties(props);
+                }
             }
         } else {
             custPart = null;
index f17a163c8aac19842f7f360d76e9cb0719af0c11..a96b8d59d0a7ecf16cac0ba83340c7ea52631f74 100644 (file)
@@ -759,8 +759,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
 
                 if (partUnmarshaller != null) {
                     UnmarshallContext context = new UnmarshallContext(this, part._partName);
-                    try {
-                        PackagePart unmarshallPart = partUnmarshaller.unmarshall(context, part.getInputStream());
+                    try (InputStream partStream = part.getInputStream()) {
+                        PackagePart unmarshallPart = partUnmarshaller.unmarshall(context, partStream);
                         partList.remove(part.getPartName());
                         partList.put(unmarshallPart._partName, unmarshallPart);
 
index 4ac65c7eaafe18eed0d7a60d4d782752e5dc6df0..b529a493a12a765252c1caab50dd13acba9da770 100644 (file)
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.openxml4j.opc;
 
+import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.*;
@@ -298,7 +299,10 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
             throws InvalidFormatException {
         try {
             LOG.atDebug().log("Parsing relationship: {}", relPart.getPartName());
-            Document xmlRelationshipsDoc = DocumentHelper.readDocument(relPart.getInputStream());
+            Document xmlRelationshipsDoc;
+            try (InputStream partStream = relPart.getInputStream()) {
+                xmlRelationshipsDoc = DocumentHelper.readDocument(partStream);
+            }
 
             // Browse default types
             Element root = xmlRelationshipsDoc.getDocumentElement();
index b317751a0a00b4fb5205b84e17db5617e6f9ac4e..a4905fc7778edb12f6c5846658fa39e47c984cb5 100644 (file)
@@ -22,6 +22,7 @@ import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.MS_DIGSIG_NS
 import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_DIGSIG_NS;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.security.cert.X509Certificate;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -99,7 +100,9 @@ public class SignaturePart {
      */
     public SignatureDocument getSignatureDocument() throws IOException, XmlException {
         // TODO: check for XXE
-        return SignatureDocument.Factory.parse(signaturePart.getInputStream(), DEFAULT_XML_OPTIONS);
+        try (InputStream stream = signaturePart.getInputStream()) {
+            return SignatureDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+        }
     }
 
     /**
@@ -113,7 +116,11 @@ public class SignaturePart {
         xpath.setNamespaceContext(new XPathNSContext());
 
         try {
-            Document doc = DocumentHelper.readDocument(signaturePart.getInputStream());
+            Document doc;
+            try (InputStream stream = signaturePart.getInputStream()) {
+                doc = DocumentHelper.readDocument(stream);
+            }
+
             NodeList nl = (NodeList)xpath.compile("//*[@Id]").evaluate(doc, XPathConstants.NODESET);
             final int length = nl.getLength();
             for (int i=0; i<length; i++) {
index 1a8daa3eb47bbb16a3e36a02dd4c6d65818c822a..4de2d38cf2eea016e1dd1eabcc1f753037bac456 100644 (file)
@@ -27,6 +27,7 @@ package org.apache.poi.poifs.crypt.dsig.services;
 import static org.apache.logging.log4j.util.Unbox.box;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.math.BigInteger;
 import java.net.HttpURLConnection;
@@ -163,7 +164,9 @@ public class TSPTimeStampService implements TimeStampService {
                 throw new RuntimeException("missing Content-Type header");
             }
 
-            responseBytes = IOUtils.toByteArray(huc.getInputStream());
+            try (InputStream stream = huc.getInputStream()) {
+                responseBytes = IOUtils.toByteArray(stream);
+            }
             LOG.atDebug().log(() -> new SimpleMessage("response content: " + HexDump.dump(responseBytes, 0, 0)));
         } finally {
             huc.disconnect();
index 4ca8b864ee262e5269bdc458773bc5ad3587f631..d660241915baff241c7bf68b9ed625ebcd7ec24b 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.poi.poifs.crypt.temp;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.logging.log4j.LogManager;
@@ -51,7 +52,9 @@ public class SXSSFWorkbookWithCustomZipEntrySource extends SXSSFWorkbook {
                 getXSSFWorkbook().write(os);
             }
             // provide ZipEntrySource to poi which decrypts on the fly
-            source = AesZipFileZipEntrySource.createZipEntrySource(tempData.getInputStream());
+            try (InputStream tempStream = tempData.getInputStream()) {
+                source = AesZipFileZipEntrySource.createZipEntrySource(tempStream);
+            }
             injectData(source, stream);
         } finally {
             tempData.dispose();
index 20bb719484ee32cd561e9b346464f63fda13574b..bfbb775296b4d1bba37885c636acda10e0e9799a 100644 (file)
@@ -1009,7 +1009,9 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
                     workbook = new XSSFWorkbook();
                     workbook.createSheet();
                 } else {
-                    workbook = new XSSFWorkbook(worksheetPart.getInputStream());
+                    try (InputStream stream = worksheetPart.getInputStream()){
+                        workbook = new XSSFWorkbook(stream);
+                    }
                 }
             } catch (NotOfficeXmlFileException e) {
                 workbook = new XSSFWorkbook();
index 2e514dab5589364bb7f8044ec1160aec9c296794..06cb573e5028978d244514722af8c106d24c7154 100644 (file)
@@ -154,9 +154,10 @@ public class XMLSlideShow extends POIXMLDocument
     @Override
     protected void onDocumentRead() throws IOException {
         try {
-            PresentationDocument doc =
-                    PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS);
-            _presentation = doc.getPresentation();
+            try (InputStream stream = getCorePart().getInputStream()) {
+                PresentationDocument doc = PresentationDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+                _presentation = doc.getPresentation();
+            }
 
             Map<String, XSLFSlideMaster> masterMap = new HashMap<>();
             Map<String, XSLFSlide> shIdMap = new HashMap<>();
index 01b98099d122a1ae8dea3b152c0d10907fae083c..4ee910d8096d7bb5734be235d2dadac48891115e 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
@@ -52,9 +53,10 @@ public class XSLFCommentAuthors extends POIXMLDocumentPart {
      */
     XSLFCommentAuthors(PackagePart part) throws IOException, XmlException {
         super(part);
-        CmAuthorLstDocument doc =
-           CmAuthorLstDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-        _authors = doc.getCmAuthorLst();
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            CmAuthorLstDocument doc = CmAuthorLstDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            _authors = doc.getCmAuthorLst();
+        }
     }
     
     public CTCommentAuthorList getCTCommentAuthorsList() {
index 00fa47d5f1261fafd7d82d709bd8c10ca0285eff..c34a6ee3d598b6a839034e2f8c4b01875343543c 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
@@ -50,7 +51,9 @@ public class XSLFComments extends POIXMLDocumentPart {
     XSLFComments(PackagePart part) throws IOException, XmlException {
         super(part);
 
-        doc = CmLstDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            doc = CmLstDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+        }
     }
 
     public CTCommentList getCTCommentsList() {
index 5912d0574523c9d6b603b1df39a206e67defa518..c01b9ff3de0c77ab661b6f320ec47e78d2581779 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -49,9 +50,11 @@ public class XSLFMetroShape implements MetroShapeProvider {
             if (shapePart == null) {
                 return null;
             }
-            CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), DEFAULT_XML_OPTIONS);
-            XSLFGroupShape xgs = new XSLFGroupShape(gs, null);
-            return xgs.getShapes().get(0);
+            try (InputStream stream = shapePart.getInputStream()) {
+                CTGroupShape gs = CTGroupShape.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+                XSLFGroupShape xgs = new XSLFGroupShape(gs, null);
+                return xgs.getShapes().get(0);
+            }
         } catch (InvalidFormatException | XmlException e) {
             throw new IOException("can't parse metro shape", e);
         }
index dfdad6fe197af94093bcd8884e76012a884b4b2b..2abbc340b0031291003e44e8c7f92cbad1365079 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -54,9 +55,10 @@ implements Notes<XSLFShape,XSLFTextParagraph> {
     XSLFNotes(PackagePart part) throws IOException, XmlException {
         super(part);
 
-        NotesDocument doc =
-            NotesDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-        _notes = doc.getNotes();
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            NotesDocument doc = NotesDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            _notes = doc.getNotes();
+        }
     }
 
     private static CTNotesSlide prototype(){
index b3bd64f3482b8d499eba25e60dc1f8ef30651fd8..fd1cbfb21cda37f66c7f6e9b7955a450b6cdd99f 100644 (file)
@@ -58,9 +58,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
      */
     protected XSLFNotesMaster(PackagePart part) throws IOException, XmlException {
         super(part);
-        NotesMasterDocument doc =
-            NotesMasterDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-        _slide = doc.getNotesMaster();
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            NotesMasterDocument doc = NotesMasterDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            _slide = doc.getNotesMaster();
+        }
     }
 
     private static CTNotesMaster prototype() {
index 446ab8af7bcab7be60279893253145fafbc85b50..f7f4e8dc1de57ce7f626c9a2b37b846cda409dca 100644 (file)
@@ -20,6 +20,7 @@ import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.awt.Graphics2D;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -78,8 +79,8 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
         super(part);
 
         Document _doc;
-        try {
-            _doc = DocumentHelper.readDocument(getPackagePart().getInputStream());
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            _doc = DocumentHelper.readDocument(stream);
         } catch (SAXException e) {
             throw new IOException(e);
         }
index 17f66bec0ad0de23c73e24b37d22400cd9dea64f..0d6b9ca47696c68e339d3712a093f4ba7b0f3e56 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
@@ -42,9 +43,10 @@ implements MasterSheet<XSLFShape,XSLFTextParagraph> {
      */
     public XSLFSlideLayout(PackagePart part) throws IOException, XmlException {
         super(part);
-        SldLayoutDocument doc =
-                SldLayoutDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-        _layout = doc.getSldLayout();
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            SldLayoutDocument doc = SldLayoutDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            _layout = doc.getSldLayout();
+        }
     }
 
     public String getName() {
index c473fa23894e677bb971b4fb774533c4953049af..0031225e75d705a757d6ad895860aad93622a648 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -61,9 +62,11 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
      */
     protected XSLFSlideMaster(PackagePart part) throws IOException, XmlException {
         super(part);
-        SldMasterDocument doc =
-            SldMasterDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-        _slide = doc.getSldMaster();
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            SldMasterDocument doc = SldMasterDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            _slide = doc.getSldMaster();
+
+        }
     }
 
     @Override
index f7719d307380e11d653709a93576297e8871ea49..79ffdb1c44ce108b094a6a150eb28c7455e46886 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -65,7 +66,7 @@ public class XSLFSlideShow extends POIXMLDocument {
     /**
      * The embedded OLE2 files in the OPC package
      */
-    private final List<PackagePart> embedds;
+    private final List<PackagePart> embeddedParts;
 
     public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
         super(container);
@@ -74,10 +75,12 @@ public class XSLFSlideShow extends POIXMLDocument {
             rebase(getPackage());
         }
 
-        presentationDoc =
-            PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS);
+        try (InputStream stream = getCorePart().getInputStream()) {
+            presentationDoc =
+                    PresentationDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+        }
 
-        embedds = new LinkedList<>();
+        embeddedParts = new LinkedList<>();
         for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) {
             PackagePart corePart = getCorePart();
             PackagePart slidePart = corePart.getRelatedPart(corePart.getRelationship(ctSlide.getId2()));
@@ -87,14 +90,15 @@ public class XSLFSlideShow extends POIXMLDocument {
                     continue;
                 }
                 // TODO: Add this reference to each slide as well
-                embedds.add(slidePart.getRelatedPart(rel));
+                embeddedParts.add(slidePart.getRelatedPart(rel));
             }
 
             for (PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
-                embedds.add(slidePart.getRelatedPart(rel));
+                embeddedParts.add(slidePart.getRelatedPart(rel));
             }
         }
     }
+
     public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException {
         this(openPackage(file));
     }
@@ -149,9 +153,11 @@ public class XSLFSlideShow extends POIXMLDocument {
     @Internal
     public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
         PackagePart masterPart = getSlideMasterPart(master);
-        SldMasterDocument masterDoc =
-            SldMasterDocument.Factory.parse(masterPart.getInputStream(), DEFAULT_XML_OPTIONS);
-        return masterDoc.getSldMaster();
+        try (InputStream stream = masterPart.getInputStream()) {
+            SldMasterDocument masterDoc =
+                    SldMasterDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            return masterDoc.getSldMaster();
+        }
     }
 
     public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException {
@@ -169,9 +175,10 @@ public class XSLFSlideShow extends POIXMLDocument {
     @Internal
     public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
         PackagePart slidePart = getSlidePart(slide);
-        SldDocument slideDoc =
-            SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS);
-        return slideDoc.getSld();
+        try (InputStream stream = slidePart.getInputStream()) {
+            SldDocument slideDoc = SldDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            return slideDoc.getSld();
+        }
     }
 
     /**
@@ -212,10 +219,10 @@ public class XSLFSlideShow extends POIXMLDocument {
         if(notesPart == null)
             return null;
 
-        NotesDocument notesDoc =
-            NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS);
-
-        return notesDoc.getNotes();
+        try (InputStream stream = notesPart.getInputStream()) {
+            NotesDocument notesDoc = NotesDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            return notesDoc.getNotes();
+        }
     }
 
     /**
@@ -244,9 +251,10 @@ public class XSLFSlideShow extends POIXMLDocument {
             PackagePart cPart = slidePart.getRelatedPart(
                     commentRels.getRelationship(0)
             );
-            CmLstDocument commDoc =
-                CmLstDocument.Factory.parse(cPart.getInputStream(), DEFAULT_XML_OPTIONS);
-            return commDoc.getCmLst();
+            try (InputStream stream = cPart.getInputStream()) {
+                CmLstDocument commDoc = CmLstDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+                return commDoc.getCmLst();
+            }
         } catch(InvalidFormatException e) {
             throw new IllegalStateException(e);
         }
@@ -257,7 +265,7 @@ public class XSLFSlideShow extends POIXMLDocument {
      */
     @Override
     public List<PackagePart> getAllEmbeddedParts() throws OpenXML4JException {
-        return embedds;
+        return embeddedParts;
     }
 
 }
index 556ad6e6e764893f9f8a63004ced2b8bc69d33e9..c8deecdc66895a4b1ac9657417b936999cfcf5b0 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
 import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import javax.xml.namespace.QName;
@@ -51,9 +52,10 @@ public class XSLFTheme extends POIXMLDocumentPart {
      */
     public XSLFTheme(PackagePart part) throws IOException, XmlException {
         super(part);
-        ThemeDocument doc =
-            ThemeDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-        _theme = doc.getTheme();
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            ThemeDocument doc = ThemeDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            _theme = doc.getTheme();
+        }
     }
 
     @SuppressWarnings("WeakerAccess")
index 9a058eb8a5bdfd1775884ace2a67a04105d0a74b..4f668aa0f7bd44dd7e3a34d197f0817fc01b25e4 100644 (file)
@@ -296,8 +296,8 @@ public class XSSFReader {
                 throw new POIXMLException(e);
             }
             xmlReader.setContentHandler(xmlSheetRefReader);
-            try {
-                xmlReader.parse(new InputSource(wb.getInputStream()));
+            try (InputStream stream = wb.getInputStream()) {
+                xmlReader.parse(new InputSource(stream));
             } catch (SAXException e) {
                 throw new POIXMLException(e);
             }
index e90c7a5c97fe6d9058a4b9f324f4a5a436a569a0..9f69900ec808b0f8a231f1ba6fcd2a5b46c373ee 100644 (file)
@@ -145,8 +145,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
      */
     @Override
     protected void onDocumentRead() {
-        try {
-            read(getPackagePart().getInputStream());
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            read(stream);
         } catch (IOException e){
             throw new POIXMLException(e);
         }
index 640534354a2dd1f9acb8c068e3dcb77e864ecfba..ba8d5849eb65aee899d0cec1a9c49661bca47056 100644 (file)
@@ -119,7 +119,9 @@ public final class XSSFVMLDrawing extends POIXMLDocumentPart {
      */
     protected XSSFVMLDrawing(PackagePart part) throws IOException, XmlException {
         super(part);
-        read(getPackagePart().getInputStream());
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            read(stream);
+        }
     }
 
     public XmlDocument getDocument() {
index c6edf23395bdf8782659152907a21eabb36864f4..ec17fa8809345a60531c91e46ce8ab6f749485e6 100644 (file)
@@ -382,8 +382,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
     @Override
     protected void onDocumentRead() throws IOException {
         try {
-            WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-            this.workbook = doc.getWorkbook();
+            try (InputStream stream = getPackagePart().getInputStream()) {
+                WorkbookDocument doc = WorkbookDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+                this.workbook = doc.getWorkbook();
+            }
 
             ThemesTable theme = null;
             Map<String, XSSFSheet> shIdMap = new HashMap<>();
index 3530c7c5fee531af7dd0bb7e82902fed45ca3e0b..9e735bacdb131430c85f6916da858f7c53ba3cce 100644 (file)
@@ -191,8 +191,11 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
     @Override
     protected void onDocumentRead() throws IOException {
         try {
-            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
-            ctDocument = doc.getDocument();
+            DocumentDocument doc;
+            try (InputStream stream = getPackagePart().getInputStream()) {
+                doc = DocumentDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+                ctDocument = doc.getDocument();
+            }
 
             initFootnotes();
 
@@ -584,8 +587,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
             throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
         }
 
-        StylesDocument sd = StylesDocument.Factory.parse(parts[0].getInputStream(), DEFAULT_XML_OPTIONS);
-        return sd.getStyles();
+        try (InputStream stream = parts[0].getInputStream()) {
+            StylesDocument sd = StylesDocument.Factory.parse(stream, DEFAULT_XML_OPTIONS);
+            return sd.getStyles();
+        }
     }
 
     /**
index 2674b2f541fa6947e7c5b0a393fb016e2d73465d..d4ea1849b43d9add4efc878c6b0014d5ceeae528 100644 (file)
@@ -93,8 +93,8 @@ public class XWPFPictureData extends POIXMLDocumentPart {
      * @return the Picture data.
      */
     public byte[] getData() {
-        try {
-            return IOUtils.toByteArray(getPackagePart().getInputStream());
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            return IOUtils.toByteArray(stream);
         } catch (IOException e) {
             throw new POIXMLException(e);
         }
index 03b1090f73f8aa8705cf572433eb4c6779b2a21c..407af7232f57d44a8e24d738058c24bc623bd9a2 100644 (file)
@@ -63,7 +63,9 @@ public class XWPFSettings extends POIXMLDocumentPart {
     @Override
     protected void onDocumentRead() throws IOException {
         super.onDocumentRead();
-        readFrom(getPackagePart().getInputStream());
+        try (InputStream stream = getPackagePart().getInputStream()) {
+            readFrom(stream);
+        }
     }
 
     /**