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
This commit is contained in:
Dominik Stadler 2015-12-30 20:31:30 +00:00
parent 8ae2972f3d
commit e4b168d27f
2 changed files with 21 additions and 9 deletions

View 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 {

View 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())));
}