String contentType = pPart.getContentType();
if (contentType.equals("application/vnd.ms-excel")) {
// Excel Workbook - either binary or OpenXML
- HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(pPart.getInputStream());
- embeddedWorkbook.close();
+ try (InputStream stream = pPart.getInputStream()) {
+ HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(stream);
+ embeddedWorkbook.close();
+ }
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
// Excel Workbook - OpenXML file format
- XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(pPart.getInputStream());
- embeddedWorkbook.close();
+ try (InputStream stream = pPart.getInputStream()) {
+ XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(stream);
+ embeddedWorkbook.close();
+ }
} else if (contentType.equals("application/msword")) {
// Word Document - binary (OLE2CDF) file format
- HWPFDocument document = new HWPFDocument(pPart.getInputStream());
- document.close();
+ try (InputStream stream = pPart.getInputStream()) {
+ HWPFDocument document = new HWPFDocument(stream);
+ document.close();
+ }
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
// Word Document - OpenXML file format
- XWPFDocument document = new XWPFDocument(pPart.getInputStream());
- document.close();
+ try (InputStream stream = pPart.getInputStream()) {
+ XWPFDocument document = new XWPFDocument(stream);
+ document.close();
+ }
} else if (contentType.equals("application/vnd.ms-powerpoint")) {
// PowerPoint Document - binary file format
- HSLFSlideShow slideShow = new HSLFSlideShow(pPart.getInputStream());
- slideShow.close();
+ try (InputStream stream = pPart.getInputStream()) {
+ HSLFSlideShow slideShow = new HSLFSlideShow(stream);
+ slideShow.close();
+ }
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
// PowerPoint Document - OpenXML file format
- XMLSlideShow slideShow = new XMLSlideShow(pPart.getInputStream());
- slideShow.close();
+ try (InputStream stream = pPart.getInputStream()) {
+ XMLSlideShow slideShow = new XMLSlideShow(stream);
+ slideShow.close();
+ }
} else {
// Any other type of embedded object.
System.out.println("Unknown Embedded Document: " + contentType);
- InputStream inputStream = pPart.getInputStream();
- inputStream.close();
+ try (InputStream inputStream = pPart.getInputStream()) {
+
+ }
}
}
}
ext.setUri("{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}");\r
String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main";\r
XmlCursor cur = ext.newCursor();\r
- cur.toEndToken();\r
- cur.beginElement(new QName(p14Ns, "media", "p14"));\r
- cur.insertNamespace("p14", p14Ns);\r
- cur.insertAttributeWithValue(new QName(STRelationshipId.type.getName().getNamespaceURI(), "embed"), prsEmbed1.getId());\r
- cur.beginElement(new QName(p14Ns, "trim", "p14"));\r
- cur.insertAttributeWithValue("st", df_time.format(seconds*1000.0));\r
- cur.dispose();\r
-\r
+ try {\r
+ cur.toEndToken();\r
+ cur.beginElement(new QName(p14Ns, "media", "p14"));\r
+ cur.insertNamespace("p14", p14Ns);\r
+ cur.insertAttributeWithValue(new QName(STRelationshipId.type.getName().getNamespaceURI(), "embed"), prsEmbed1.getId());\r
+ cur.beginElement(new QName(p14Ns, "trim", "p14"));\r
+ cur.insertAttributeWithValue("st", df_time.format(seconds*1000.0));\r
+ } finally {\r
+ cur.dispose();\r
+ }\r
}\r
\r
static void addTimingInfo(XSLFSlide slide1, XSLFPictureShape pic1) {\r
String p14Ns = "http://schemas.microsoft.com/office/powerpoint/2010/main";
XmlCursor cur = ext.newCursor();
- cur.toEndToken();
- cur.beginElement(new QName(p14Ns, "media", "p14"));
- cur.insertNamespace("p14", p14Ns);
- cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId());
- cur.dispose();
-
+ try {
+ cur.toEndToken();
+ cur.beginElement(new QName(p14Ns, "media", "p14"));
+ cur.insertNamespace("p14", p14Ns);
+ cur.insertAttributeWithValue(new QName(CORE_PROPERTIES_ECMA376_NS, "link"), prsEmbed1.getId());
+ } finally {
+ cur.dispose();
+ }
CTSlide xslide = slide1.getXmlObject();
CTTimeNodeList ctnl;