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());
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());
public static Iterable<Object[]> files() {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(ROOT_DIR);
- scanner.setExcludes(new String[] { "**/.svn/**" });
+ scanner.setExcludes(SCAN_EXCLUDES);
scanner.scan();
}
}
- 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 {
// 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");
// and finally ensure that exporting to XML works
exportToXML(wb);
-
- checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(out.toByteArray())));
}