From: Dominik Stadler Date: Wed, 30 Dec 2015 20:31:30 +0000 (+0000) Subject: Add null-handler in integration-tests for two Visio files which are not handled ... X-Git-Tag: REL_3_14_FINAL~133 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fcbd9b5409cb869d8f2b94df40369149fcb72ad9;p=poi.git Add null-handler in integration-tests for two Visio files which are not handled (yet) and adjust memory handling somewhat git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722408 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java index 39a2069b2c..ecf30a677d 100644 --- a/src/integrationtest/org/apache/poi/TestAllFiles.java +++ b/src/integrationtest/org/apache/poi/TestAllFiles.java @@ -68,8 +68,10 @@ import org.junit.runners.Parameterized.Parameters; public class TestAllFiles { private static final File ROOT_DIR = new File("test-data"); + static final String[] SCAN_EXCLUDES = new String[] { "**/.svn/**", "lost+found" }; + // map file extensions to the actual mappers - private static final Map HANDLERS = new HashMap(); + static final Map HANDLERS = new HashMap(); static { // Excel HANDLERS.put(".xls", new HSSFFileHandler()); @@ -113,6 +115,10 @@ public class TestAllFiles { HANDLERS.put(".vstm", new XDGFFileHandler()); HANDLERS.put(".vstx", new XDGFFileHandler()); + // Visio - not handled yet + HANDLERS.put(".vst", new NullFileHandler()); + HANDLERS.put(".vss", new NullFileHandler()); + // POIFS HANDLERS.put(".ole2", new POIFSFileHandler()); @@ -268,7 +274,7 @@ public class TestAllFiles { public static Iterable files() { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(ROOT_DIR); - scanner.setExcludes(new String[] { "**/.svn/**" }); + scanner.setExcludes(SCAN_EXCLUDES); scanner.scan(); @@ -343,13 +349,13 @@ public class TestAllFiles { } } - private static String getExtension(String file) { + static String getExtension(String file) { int pos = file.lastIndexOf('.'); if(pos == -1 || pos == file.length()-1) { return file; } - return file.substring(pos); + return file.substring(pos).toLowerCase(); } private static class NullFileHandler implements FileHandler { diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java index 764ca4ac75..414809c00c 100644 --- a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java @@ -47,10 +47,18 @@ public class XSSFFileHandler extends SpreadsheetHandler { // ignore password protected files if (POIXMLDocumentHandler.isEncrypted(stream)) return; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - IOUtils.copy(stream, out); + final XSSFWorkbook wb; - XSSFWorkbook wb = new XSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); + // make sure the potentially large byte-array is freed up quickly again + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + IOUtils.copy(stream, out); + final byte[] bytes = out.toByteArray(); + + checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(bytes))); + + wb = new XSSFWorkbook(new ByteArrayInputStream(bytes)); + } // use the combined handler for HSSF/XSSF handleWorkbook(wb, ".xlsx"); @@ -64,8 +72,6 @@ public class XSSFFileHandler extends SpreadsheetHandler { // and finally ensure that exporting to XML works exportToXML(wb); - - checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(out.toByteArray()))); }