aboutsummaryrefslogtreecommitdiffstats
path: root/src/integrationtest
diff options
context:
space:
mode:
Diffstat (limited to 'src/integrationtest')
-rw-r--r--src/integrationtest/org/apache/poi/TestAllFiles.java9
-rw-r--r--src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java29
-rw-r--r--src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java5
-rw-r--r--src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java5
-rw-r--r--src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java5
-rw-r--r--src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java16
-rw-r--r--src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java17
-rw-r--r--src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java5
-rw-r--r--src/integrationtest/org/apache/poi/stress/OPCFileHandler.java9
-rw-r--r--src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java23
-rw-r--r--src/integrationtest/org/apache/poi/stress/SlideShowHandler.java5
-rw-r--r--src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java5
-rw-r--r--src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java22
-rw-r--r--src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java10
-rw-r--r--src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java19
-rw-r--r--src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java5
16 files changed, 50 insertions, 139 deletions
diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java
index db543ce180..77651274e4 100644
--- a/src/integrationtest/org/apache/poi/TestAllFiles.java
+++ b/src/integrationtest/org/apache/poi/TestAllFiles.java
@@ -405,13 +405,10 @@ public class TestAllFiles {
boolean ignoreHPSF = (handler instanceof HPSFFileHandler);
try {
- InputStream stream = new BufferedInputStream(new FileInputStream(inputFile), 64*1024);
- try {
+ try (InputStream stream = new BufferedInputStream(new FileInputStream(inputFile), 64 * 1024)) {
handler.handleFile(stream, file);
- assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!",
- OLD_FILES_HWPF.contains(file) && !ignoreHPSF);
- } finally {
- stream.close();
+ assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!",
+ OLD_FILES_HWPF.contains(file) && !ignoreHPSF);
}
handler.handleExtracting(inputFile);
diff --git a/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java b/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
index ad2150c7f2..e040f1e5f4 100644
--- a/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
@@ -99,16 +99,13 @@ public abstract class AbstractFileHandler implements FileHandler {
handleExtractingAsStream(file);
if(extractor instanceof POIOLE2TextExtractor) {
- HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor)extractor);
- try {
- assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
- assertNotNull(hpsfExtractor.getSummaryInformationText());
- String text = hpsfExtractor.getText();
- //System.out.println(text);
- assertNotNull(text);
- } finally {
- hpsfExtractor.close();
- }
+ try (HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
+ assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
+ assertNotNull(hpsfExtractor.getSummaryInformationText());
+ String text = hpsfExtractor.getText();
+ //System.out.println(text);
+ assertNotNull(text);
+ }
}
} catch (IllegalArgumentException e) {
if(!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
@@ -124,18 +121,12 @@ public abstract class AbstractFileHandler implements FileHandler {
}
private void handleExtractingAsStream(File file) throws IOException, OpenXML4JException, XmlException {
- InputStream stream = new FileInputStream(file);
- try {
- POITextExtractor streamExtractor = ExtractorFactory.createExtractor(stream);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
+ try (POITextExtractor streamExtractor = ExtractorFactory.createExtractor(stream)) {
assertNotNull(streamExtractor);
-
+
assertNotNull(streamExtractor.getText());
- } finally {
- streamExtractor.close();
}
- } finally {
- stream.close();
}
}
diff --git a/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java
index a325f0d5ea..5482949e52 100644
--- a/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java
@@ -68,11 +68,8 @@ public class HDGFFileHandler extends POIFSFileHandler {
stream = new FileInputStream(file);
try {
- VisioTextExtractor extractor = new VisioTextExtractor(stream);
- try {
+ try (VisioTextExtractor extractor = new VisioTextExtractor(stream)) {
assertNotNull(extractor.getText());
- } finally {
- extractor.close();
}
} finally {
stream.close();
diff --git a/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
index 4532ab0503..c61a001376 100644
--- a/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
@@ -51,11 +51,8 @@ public class HMEFFileHandler extends AbstractFileHandler {
@Test
public void test() throws Exception {
String path = "test-data/hmef/quick-winmail.dat";
- InputStream stream = new FileInputStream(path);
- try {
+ try (InputStream stream = new FileInputStream(path)) {
handleFile(stream, path);
- } finally {
- stream.close();
}
}
}
diff --git a/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java
index 788f9da613..3fc03b0bc2 100644
--- a/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java
@@ -56,11 +56,8 @@ public class HPBFFileHandler extends POIFSFileHandler {
stream = new FileInputStream(file);
try {
- PublisherTextExtractor extractor = new PublisherTextExtractor(stream);
- try {
+ try (PublisherTextExtractor extractor = new PublisherTextExtractor(stream)) {
assertNotNull(extractor.getText());
- } finally {
- extractor.close();
}
} finally {
stream.close();
diff --git a/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java
index cf0ebd0943..a5baa4adbc 100644
--- a/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java
@@ -88,11 +88,8 @@ public class HPSFFileHandler extends POIFSFileHandler {
if (!root.hasEntry(streamName)) {
return false;
}
- DocumentInputStream dis = root.createDocumentInputStream(streamName);
- try {
- return PropertySet.isPropertySetStream(dis);
- } finally {
- dis.close();
+ try (DocumentInputStream dis = root.createDocumentInputStream(streamName)) {
+ return PropertySet.isPropertySetStream(dis);
}
}
@@ -122,12 +119,9 @@ public class HPSFFileHandler extends POIFSFileHandler {
@Test
public void test() throws Exception {
String path = "test-data/hpsf/Test0313rur.adm";
- InputStream stream = new FileInputStream(path);
- try {
- handleFile(stream, path);
- } finally {
- stream.close();
- }
+ try (InputStream stream = new FileInputStream(path)) {
+ handleFile(stream, path);
+ }
}
// a test-case to test this locally without executing the full TestAllFiles
diff --git a/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java
index 1d075df895..15209d3d76 100644
--- a/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java
@@ -58,12 +58,7 @@ public class HSLFFileHandler extends SlideShowHandler {
@Override
@Test
public void test() throws Exception {
- File[] files = new File("test-data/slideshow/").listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".ppt");
- }
- });
+ File[] files = new File("test-data/slideshow/").listFiles((dir, name) -> name.endsWith(".ppt"));
assertNotNull(files);
System.out.println("Testing " + files.length + " files");
@@ -82,11 +77,8 @@ public class HSLFFileHandler extends SlideShowHandler {
System.out.println(file);
//System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
- InputStream stream = new FileInputStream(file);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);
@@ -94,11 +86,8 @@ public class HSLFFileHandler extends SlideShowHandler {
public static void main(String[] args) throws Exception {
System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
- InputStream stream = new FileInputStream(args[0]);
- try {
+ try (InputStream stream = new FileInputStream(args[0])) {
new HSLFFileHandler().handleFile(stream, args[0]);
- } finally {
- stream.close();
}
}
}
diff --git a/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java
index 61d10789cb..2aa02ed373 100644
--- a/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java
@@ -79,11 +79,8 @@ public class HSMFFileHandler extends POIFSFileHandler {
@Test
public void test() throws Exception {
File file = new File("test-data/hsmf/logsat.com_signatures_valid.msg");
- InputStream stream = new FileInputStream(file);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);
diff --git a/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java b/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java
index cd9e93c092..fe0d547ebb 100644
--- a/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java
@@ -65,12 +65,9 @@ public class OPCFileHandler extends AbstractFileHandler {
public void test() throws Exception {
File file = new File("test-data/diagram/test.vsdx");
- InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
- try {
- handleFile(stream, file.getPath());
- } finally {
- stream.close();
- }
+ try (InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000)) {
+ handleFile(stream, file.getPath());
+ }
handleExtracting(file);
}
diff --git a/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java b/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java
index 309949b33f..09460cd76f 100644
--- a/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java
@@ -34,27 +34,21 @@ public class POIFSFileHandler extends AbstractFileHandler {
@Override
public void handleFile(InputStream stream, String path) throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(stream);
- try {
- handlePOIFSFileSystem(fs);
- handleHPSFProperties(fs);
- } finally {
- fs.close();
- }
+ try (POIFSFileSystem fs = new POIFSFileSystem(stream)) {
+ handlePOIFSFileSystem(fs);
+ handleHPSFProperties(fs);
+ }
}
private void handleHPSFProperties(POIFSFileSystem fs) throws IOException {
- HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
- try {
+ try (HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs)) {
// can be null
ext.getDocSummaryInformation();
ext.getSummaryInformation();
-
+
assertNotNull(ext.getDocumentSummaryInformationText());
assertNotNull(ext.getSummaryInformationText());
assertNotNull(ext.getText());
- } finally {
- ext.close();
}
}
@@ -78,11 +72,8 @@ public class POIFSFileHandler extends AbstractFileHandler {
public void test() throws Exception {
File file = new File("test-data/poifs/Notes.ole2");
- InputStream stream = new FileInputStream(file);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
//handleExtracting(file);
diff --git a/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java b/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
index 5241b8089d..63ffdbd58c 100644
--- a/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
@@ -51,12 +51,9 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
readContent(ss);
// read in the written file
- SlideShow<?,?> read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray()));
- try {
+ try (SlideShow<?, ?> read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray()))) {
assertNotNull(read);
readContent(read);
- } finally {
- read.close();
}
}
diff --git a/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java
index a9845b6fda..302a5d2b76 100644
--- a/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java
@@ -36,12 +36,9 @@ public class XDGFFileHandler extends AbstractFileHandler {
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
- OPCPackage pkg = OPCPackage.open("test-data/diagram/test.vsdx", PackageAccess.READ);
- try {
+ try (OPCPackage pkg = OPCPackage.open("test-data/diagram/test.vsdx", PackageAccess.READ)) {
XmlVisioDocument doc = new XmlVisioDocument(pkg);
new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
- } finally {
- pkg.close();
}
}
} \ No newline at end of file
diff --git a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
index a45dead450..043d390990 100644
--- a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
@@ -52,17 +52,14 @@ public class XSLFFileHandler extends SlideShowHandler {
// additionally try the other getText() methods
-
- XSLFPowerPointExtractor extractor = (XSLFPowerPointExtractor) ExtractorFactory.createExtractor(file);
- try {
- assertNotNull(extractor);
- assertNotNull(extractor.getText(true, true, true));
- assertEquals("With all options disabled we should not get text",
- "", extractor.getText(false, false, false));
- } finally {
- extractor.close();
- }
+ try (XSLFPowerPointExtractor extractor = (XSLFPowerPointExtractor) ExtractorFactory.createExtractor(file)) {
+ assertNotNull(extractor);
+
+ assertNotNull(extractor.getText(true, true, true));
+ assertEquals("With all options disabled we should not get text",
+ "", extractor.getText(false, false, false));
+ }
}
// a test-case to test this locally without executing the full TestAllFiles
@@ -70,11 +67,8 @@ public class XSLFFileHandler extends SlideShowHandler {
@Test
public void test() throws Exception {
File file = new File("test-data/slideshow/ae.ac.uaeu.faculty_nafaachbili_GeomLec1.pptx");
- InputStream stream = new FileInputStream(file);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);
diff --git a/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java
index fd58c12e80..b728828c4f 100644
--- a/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java
@@ -39,11 +39,8 @@ public class XSSFBFileHandler extends AbstractFileHandler {
IOUtils.copy(stream, out);
final byte[] bytes = out.toByteArray();
- OPCPackage opcPackage = OPCPackage.open(new ByteArrayInputStream(bytes));
- try {
+ try (OPCPackage opcPackage = OPCPackage.open(new ByteArrayInputStream(bytes))) {
testOne(opcPackage);
- } finally {
- opcPackage.close();
}
testNotHandledByWorkbookException(OPCPackage.open(new ByteArrayInputStream(bytes)));
@@ -86,11 +83,8 @@ public class XSSFBFileHandler extends AbstractFileHandler {
@Test
public void testLocal() throws Exception {
File file = new File("test-data/spreadsheet/Simple.xlsb");
- FileInputStream stream = new FileInputStream(file);
- try {
+ try (FileInputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);
}
diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
index b8bb0b57b0..1d4db0ae2b 100644
--- a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
@@ -195,19 +195,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
} catch (OLE2NotOfficeXmlFileException e) {
// we have some files that are not actually OOXML and thus cannot be tested here
- } catch (IllegalArgumentException e) {
- if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
- throw e;
- }
- } catch (InvalidFormatException e) {
- if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
- throw e;
- }
- } catch (IOException e) {
- if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
- throw e;
- }
- } catch (POIXMLException e) {
+ } catch (IllegalArgumentException | InvalidFormatException | POIXMLException | IOException e) {
if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
throw e;
}
@@ -221,11 +209,8 @@ public class XSSFFileHandler extends SpreadsheetHandler {
public void test() throws Exception {
File file = new File("test-data/spreadsheet/ref-56737.xlsx");
- InputStream stream = new BufferedInputStream(new FileInputStream(file));
- try {
+ try (InputStream stream = new BufferedInputStream(new FileInputStream(file))) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);
diff --git a/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java
index c3615713c2..069cbee53e 100644
--- a/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java
@@ -40,11 +40,8 @@ public class XWPFFileHandler extends AbstractFileHandler {
public void test() throws Exception {
File file = new File("test-data/document/51921-Word-Crash067.docx");
- InputStream stream = new BufferedInputStream(new FileInputStream(file));
- try {
+ try (InputStream stream = new BufferedInputStream(new FileInputStream(file))) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);