aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ooxml/java')
-rw-r--r--src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java10
-rw-r--r--src/ooxml/java/org/apache/poi/util/SAXHelper.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java12
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java4
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java7
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java4
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java2
7 files changed, 18 insertions, 34 deletions
diff --git a/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java b/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
index 1b2fa0e489..f598dc0066 100644
--- a/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
+++ b/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
@@ -167,13 +167,10 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
protected EmbeddedData extract(DirectoryNode dn) throws IOException {
assert(canExtract(dn));
ByteArrayOutputStream bos = new ByteArrayOutputStream(20000);
- POIFSFileSystem dest = new POIFSFileSystem();
- try {
+ try (POIFSFileSystem dest = new POIFSFileSystem()) {
copyNodes(dn, dest.getRoot());
// start with a reasonable big size
dest.writeFilesystem(bos);
- } finally {
- dest.close();
}
return new EmbeddedData(dn.getName(), bos.toByteArray(), CONTENT_TYPE_BYTES);
@@ -369,11 +366,8 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
destDir.setStorageClsid(srcDir.getStorageClsid());
copyNodes(srcDir, destDir);
} else {
- InputStream is = src.createDocumentInputStream(e);
- try {
+ try (InputStream is = src.createDocumentInputStream(e)) {
dest.createDocument(e.getName(), is);
- } finally {
- is.close();
}
}
}
diff --git a/src/ooxml/java/org/apache/poi/util/SAXHelper.java b/src/ooxml/java/org/apache/poi/util/SAXHelper.java
index 81ab5599fc..b5968d9ff9 100644
--- a/src/ooxml/java/org/apache/poi/util/SAXHelper.java
+++ b/src/ooxml/java/org/apache/poi/util/SAXHelper.java
@@ -66,19 +66,16 @@ public final class SAXHelper {
saxFactory = SAXParserFactory.newInstance();
saxFactory.setValidating(false);
saxFactory.setNamespaceAware(true);
- } catch (RuntimeException re) {
+ } catch (RuntimeException | Error re) {
+ // this also catches NoClassDefFoundError, which may be due to a local class path issue
+ // This may occur if the code is run inside a web container
+ // or a restricted JVM
+ // See bug 61170: https://bz.apache.org/bugzilla/show_bug.cgi?id=61170
logger.log(POILogger.WARN, "Failed to create SAXParserFactory", re);
throw re;
} catch (Exception e) {
logger.log(POILogger.WARN, "Failed to create SAXParserFactory", e);
throw new RuntimeException("Failed to create SAXParserFactory", e);
- } catch (Error e) {
- // catches NoClassDefFoundError, which may be due to a local class path issue
- // This may occur if the code is run inside a web container
- // or a restricted JVM
- // See bug 61170: https://bz.apache.org/bugzilla/show_bug.cgi?id=61170
- logger.log(POILogger.WARN, "Failed to create SAXParserFactory", e);
- throw e;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index 8f5dd8f84e..683ceb5ce5 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -481,7 +481,6 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
@Override
public XSLFPictureData addPicture(byte[] pictureData, PictureType format) {
XSLFPictureData img = findPictureData(pictureData);
-
if (img != null) {
return img;
}
@@ -491,13 +490,13 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
if (relType == null) {
throw new IllegalArgumentException("Picture type "+format+" is not supported.");
}
+
img = createRelationship(relType, XSLFFactory.getInstance(), imageNumber + 1, true).getDocumentPart();
img.setIndex(imageNumber);
_pictures.add(img);
- try {
- OutputStream out = img.getPackagePart().getOutputStream();
+
+ try (OutputStream out = img.getPackagePart().getOutputStream()) {
out.write(pictureData);
- out.close();
} catch (IOException e) {
throw new POIXMLException(e);
}
@@ -536,11 +535,8 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
{
int length = (int) pict.length();
byte[] data = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
- FileInputStream is = new FileInputStream(pict);
- try {
+ try (InputStream is = new FileInputStream(pict)) {
IOUtils.readFully(is, data);
- } finally {
- is.close();
}
return addPicture(data, format);
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
index 3c6ae88e0b..b2fc838547 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
@@ -360,12 +360,12 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
XSLFShape newShape;
if (shape instanceof XSLFTextBox) {
newShape = createTextBox();
+ } else if (shape instanceof XSLFFreeformShape) {
+ newShape = createFreeform();
} else if (shape instanceof XSLFAutoShape) {
newShape = createAutoShape();
} else if (shape instanceof XSLFConnectorShape) {
newShape = createConnector();
- } else if (shape instanceof XSLFFreeformShape) {
- newShape = createFreeform();
} else if (shape instanceof XSLFPictureShape) {
XSLFPictureShape p = (XSLFPictureShape)shape;
XSLFPictureData pd = p.getPictureData();
diff --git a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
index 938e966a68..79327bce4f 100644
--- a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
+++ b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
@@ -116,8 +116,7 @@ public class PPTX2PNG {
if (!quiet) {
System.out.println("Processing " + file);
}
- SlideShow<?,?> ss = SlideShowFactory.create(file, null, true);
- try {
+ try (SlideShow<?, ?> ss = SlideShowFactory.create(file, null, true)) {
List<? extends Slide<?, ?>> slides = ss.getSlides();
Set<Integer> slidenum = slideIndexes(slides.size(), slidenumStr);
@@ -160,12 +159,10 @@ public class PPTX2PNG {
File outfile = new File(outdir, outname);
ImageIO.write(img, format, outfile);
}
-
+
graphics.dispose();
img.flush();
}
- } finally {
- ss.close();
}
if (!quiet) {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 1916ef50b7..01db019b82 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -1114,7 +1114,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
/**
* Get the XSSFSheet object at the given index.
*
- * @param index of the sheet number (0-based physical & logical)
+ * @param index of the sheet number (0-based physical &amp; logical)
* @return XSSFSheet at the provided index
* @throws IllegalArgumentException if the index is out of range (index
* &lt; 0 || index &gt;= getNumberOfSheets()).
@@ -1129,7 +1129,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
* Returns the index of the sheet by his name (case insensitive match)
*
* @param name the sheet name
- * @return index of the sheet (0 based) or <tt>-1</tt if not found
+ * @return index of the sheet (0 based) or <tt>-1</tt> if not found
*/
@Override
public int getSheetIndex(String name) {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
index 50ed79313f..1656a6f878 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
@@ -96,7 +96,7 @@ import java.util.List;
* @param formulaShifter the formula shifting policy
*/
/*package*/ static void updateRowFormulas(XSSFRow row, FormulaShifter formulaShifter) {
- XSSFSheet sheet = (XSSFSheet) row.getSheet();
+ XSSFSheet sheet = row.getSheet();
for (Cell c : row) {
XSSFCell cell = (XSSFCell) c;