* <pre>
* protected void commit() throws IOException {
* PackagePart part = getPackagePart();
- * OutputStream out = part.getOutputStream();
- * XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
- * bean.save(out, DEFAULT_XML_OPTIONS);
- * out.close();
+ * try (OutputStream out = part.getOutputStream()) {
+ * XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
+ * bean.save(out, DEFAULT_XML_OPTIONS);
+ * }
* }
* </pre>
*
dest.addRelationship(part.getPartName(), rel.getTargetMode(), rel.getRelationshipType());
part_tgt = dest.createPart(part.getPartName(), part.getContentType());
- OutputStream out = part_tgt.getOutputStream();
- IOUtils.copy(part.getInputStream(), out);
- out.close();
+ try (OutputStream out = part_tgt.getOutputStream()) {
+ IOUtils.copy(part.getInputStream(), out);
+ }
if (part.hasRelationships()) {
copy(pkg, part, dest, part_tgt);
PackagePart dest;
if(!tgt.containPart(p.getPartName())){
dest = tgt.createPart(p.getPartName(), p.getContentType());
- OutputStream out = dest.getOutputStream();
- IOUtils.copy(p.getInputStream(), out);
- out.close();
+ try (
+ InputStream in = p.getInputStream();
+ OutputStream out = dest.getOutputStream()
+ ) {
+ IOUtils.copy(in, out);
+ }
copy(pkg, p, tgt, dest);
}
}
* "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
* "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
*
- * FileOutputStream out = new FileOutputStream("workbook.xlsx");
- * pkg.save(out);
- * out.close();
+ * try (FileOutputStream out = new FileOutputStream("workbook.xlsx")) {
+ * pkg.save(out);
+ * }
*
* }</pre>
*
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- _presentation.save(out, DEFAULT_XML_OPTIONS);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ _presentation.save(out, DEFAULT_XML_OPTIONS);
+ }
}
/**
}
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- getXmlObject().save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ getXmlObject().save(out, xmlOptions);
+ }
}
/**
/**
* Import a package part into this sheet.
*/
- void importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
+ void importPart(PackageRelationship srcRel, PackagePart srcPart) {
PackagePart destPP = getPackagePart();
- PackagePartName srcPPName = srcPafrt.getPartName();
+ PackagePartName srcPPName = srcPart.getPartName();
OPCPackage pkg = destPP.getPackage();
if(pkg.containPart(srcPPName)){
destPP.addRelationship(srcPPName, TargetMode.INTERNAL, srcRel.getRelationshipType());
- PackagePart part = pkg.createPart(srcPPName, srcPafrt.getContentType());
- try {
- OutputStream out = part.getOutputStream();
- InputStream is = srcPafrt.getInputStream();
+ PackagePart part = pkg.createPart(srcPPName, srcPart.getContentType());
+ try(
+ OutputStream out = part.getOutputStream();
+ InputStream is = srcPart.getInputStream();
+ ) {
IOUtils.copy(is, out);
- is.close();
- out.close();
} catch (IOException e){
throw new POIXMLException(e);
}
new QName(XSLFRelation.NS_DRAWINGML, "theme"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- getXmlObject().save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ getXmlObject().save(out, xmlOptions);
+ }
}
/**
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
/**
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.util.Internal;
+import org.apache.poi.util.Removal;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExternalDefinedName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExternalLink;
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
/**
* Returns the underlying xmlbeans object for the external
- * link table
+ * link table. Internal use only. Not currently used internally.
+ * @deprecated will be removed because we don't want to expose this (future implementations may not be
+ * XMLBeans based)
*/
+ @Internal
+ @Removal(version = "6.0.0")
public CTExternalLink getCTExternalLink(){
return link;
}
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
}
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
public CTSingleXmlCells getCTSingleXMLCells(){
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
private void initialize() {
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
}
.setSaveSyntheticDocumentElement(new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- drawing.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ drawing.save(out, xmlOptions);
+ }
}
@Override
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
- //Sets the pivotCacheDefinition tag
- xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotCacheDefinition.type.getName().
- getNamespaceURI(), "pivotCacheDefinition"));
- ctPivotCacheDefinition.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+ //Sets the pivotCacheDefinition tag
+ xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotCacheDefinition.type.getName().
+ getNamespaceURI(), "pivotCacheDefinition"));
+ ctPivotCacheDefinition.save(out, xmlOptions);
+ }
}
/**
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
- //Sets the pivotCacheDefinition tag
- xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotCacheRecords.type.getName().
- getNamespaceURI(), "pivotCacheRecords"));
- ctPivotCacheRecords.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+ //Sets the pivotCacheDefinition tag
+ xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotCacheRecords.type.getName().
+ getNamespaceURI(), "pivotCacheRecords"));
+ ctPivotCacheRecords.save(out, xmlOptions);
+ }
}
}
\ No newline at end of file
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotTableDefinition.type.getName().
getNamespaceURI(), "pivotTableDefinition"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- pivotTableDefinition.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ pivotTableDefinition.save(out, xmlOptions);
+ }
}
/**
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- write(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ write(out);
+ }
}
protected void write(OutputStream out) throws IOException {
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- writeTo(out);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ writeTo(out);
+ }
}
/**
xmlOptions.setSaveSyntheticDocumentElement(new QName(
CTComments.type.getName().getNamespaceURI(), "comments"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctComments.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctComments.save(out, xmlOptions);
+ }
}
public List<XWPFPictureData> getAllPictures() {
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctDocument.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctDocument.save(out, xmlOptions);
+ }
}
/**
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTEndnotes.type.getName().getNamespaceURI(), "endnotes"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctEndnotes.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctEndnotes.save(out, xmlOptions);
+ }
}
/**
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "ftr"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- super._getHdrFtr().save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ super._getHdrFtr().save(out, xmlOptions);
+ }
}
@Override
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctFootnotes.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctFootnotes.save(out, xmlOptions);
+ }
}
/**
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "hdr"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- super._getHdrFtr().save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ super._getHdrFtr().save(out, xmlOptions);
+ }
}
/**
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "numbering"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctNumbering.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctNumbering.save(out, xmlOptions);
+ }
}
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTSettings.type.getName().getNamespaceURI(), "settings"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctSettings.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctSettings.save(out, xmlOptions);
+ }
}
private CTDocProtect safeGetDocumentProtection() {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles"));
PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- ctStyles.save(out, xmlOptions);
- out.close();
+ try (OutputStream out = part.getOutputStream()) {
+ ctStyles.save(out, xmlOptions);
+ }
}
protected void ensureDocDefaults() {