git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896462 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_0
@@ -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; |
@@ -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); | |||
@@ -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(); |
@@ -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++) { |
@@ -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(); |
@@ -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(); |
@@ -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(); |
@@ -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<>(); |
@@ -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() { |
@@ -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() { |
@@ -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); | |||
} |
@@ -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(){ |
@@ -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() { |
@@ -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); | |||
} |
@@ -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() { |
@@ -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 |
@@ -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; | |||
} | |||
} |
@@ -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") |
@@ -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); | |||
} |
@@ -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); | |||
} |
@@ -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() { |
@@ -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<>(); |
@@ -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(); | |||
} | |||
} | |||
/** |
@@ -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); | |||
} |
@@ -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); | |||
} | |||
} | |||
/** |