]> source.dussan.org Git - poi.git/commitdiff
Add null-handler in integration-tests for two Visio files which are not handled ...
authorDominik Stadler <centic@apache.org>
Wed, 30 Dec 2015 20:31:30 +0000 (20:31 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 30 Dec 2015 20:31:30 +0000 (20:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722408 13f79535-47bb-0310-9956-ffa450edef68

src/integrationtest/org/apache/poi/TestAllFiles.java
src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java

index 39a2069b2c4e6aff450c087bcf5a5ca1f7061b8b..ecf30a677dbdbe80467b41e972692c9f6d254ebb 100644 (file)
@@ -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<String, FileHandler> HANDLERS = new HashMap<String, FileHandler>();
+    static final Map<String, FileHandler> HANDLERS = new HashMap<String, FileHandler>();
     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<Object[]> 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 {
index 764ca4ac755ee777fdcd2dc4b026848ebd24e887..414809c00c5b979114432c83bb8b6b0fb6274dc8 100644 (file)
@@ -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())));
     }