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;
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;
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);
==================================================================== */
package org.apache.poi.openxml4j.opc;
+import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
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();
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;
*/
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);
+ }
}
/**
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++) {
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;
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();
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;
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();
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();
@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<>();
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;
*/
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() {
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;
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() {
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;
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);
}
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;
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(){
*/
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() {
import java.awt.Graphics2D;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
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);
}
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;
*/
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() {
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;
*/
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
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;
/**
* 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);
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()));
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));
}
@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 {
@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();
+ }
}
/**
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();
+ }
}
/**
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);
}
*/
@Override
public List<PackagePart> getAllEmbeddedParts() throws OpenXML4JException {
- return embedds;
+ return embeddedParts;
}
}
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;
*/
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")
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);
}
*/
@Override
protected void onDocumentRead() {
- try {
- read(getPackagePart().getInputStream());
+ try (InputStream stream = getPackagePart().getInputStream()) {
+ read(stream);
} catch (IOException e){
throw new POIXMLException(e);
}
*/
protected XSSFVMLDrawing(PackagePart part) throws IOException, XmlException {
super(part);
- read(getPackagePart().getInputStream());
+ try (InputStream stream = getPackagePart().getInputStream()) {
+ read(stream);
+ }
}
public XmlDocument getDocument() {
@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<>();
@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();
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();
+ }
}
/**
* @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);
}
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
- readFrom(getPackagePart().getInputStream());
+ try (InputStream stream = getPackagePart().getInputStream()) {
+ readFrom(stream);
+ }
}
/**