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:
parent
8ae2972f3d
commit
e4b168d27f
@ -68,8 +68,10 @@ import org.junit.runners.Parameterized.Parameters;
|
|||||||
public class TestAllFiles {
|
public class TestAllFiles {
|
||||||
private static final File ROOT_DIR = new File("test-data");
|
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
|
// 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 {
|
static {
|
||||||
// Excel
|
// Excel
|
||||||
HANDLERS.put(".xls", new HSSFFileHandler());
|
HANDLERS.put(".xls", new HSSFFileHandler());
|
||||||
@ -113,6 +115,10 @@ public class TestAllFiles {
|
|||||||
HANDLERS.put(".vstm", new XDGFFileHandler());
|
HANDLERS.put(".vstm", new XDGFFileHandler());
|
||||||
HANDLERS.put(".vstx", new XDGFFileHandler());
|
HANDLERS.put(".vstx", new XDGFFileHandler());
|
||||||
|
|
||||||
|
// Visio - not handled yet
|
||||||
|
HANDLERS.put(".vst", new NullFileHandler());
|
||||||
|
HANDLERS.put(".vss", new NullFileHandler());
|
||||||
|
|
||||||
// POIFS
|
// POIFS
|
||||||
HANDLERS.put(".ole2", new POIFSFileHandler());
|
HANDLERS.put(".ole2", new POIFSFileHandler());
|
||||||
|
|
||||||
@ -268,7 +274,7 @@ public class TestAllFiles {
|
|||||||
public static Iterable<Object[]> files() {
|
public static Iterable<Object[]> files() {
|
||||||
DirectoryScanner scanner = new DirectoryScanner();
|
DirectoryScanner scanner = new DirectoryScanner();
|
||||||
scanner.setBasedir(ROOT_DIR);
|
scanner.setBasedir(ROOT_DIR);
|
||||||
scanner.setExcludes(new String[] { "**/.svn/**" });
|
scanner.setExcludes(SCAN_EXCLUDES);
|
||||||
|
|
||||||
scanner.scan();
|
scanner.scan();
|
||||||
|
|
||||||
@ -343,13 +349,13 @@ public class TestAllFiles {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getExtension(String file) {
|
static String getExtension(String file) {
|
||||||
int pos = file.lastIndexOf('.');
|
int pos = file.lastIndexOf('.');
|
||||||
if(pos == -1 || pos == file.length()-1) {
|
if(pos == -1 || pos == file.length()-1) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
return file.substring(pos);
|
return file.substring(pos).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NullFileHandler implements FileHandler {
|
private static class NullFileHandler implements FileHandler {
|
||||||
|
@ -47,10 +47,18 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
|||||||
// ignore password protected files
|
// ignore password protected files
|
||||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
|
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
final XSSFWorkbook wb;
|
||||||
IOUtils.copy(stream, out);
|
|
||||||
|
|
||||||
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
|
// use the combined handler for HSSF/XSSF
|
||||||
handleWorkbook(wb, ".xlsx");
|
handleWorkbook(wb, ".xlsx");
|
||||||
@ -64,8 +72,6 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
|||||||
|
|
||||||
// and finally ensure that exporting to XML works
|
// and finally ensure that exporting to XML works
|
||||||
exportToXML(wb);
|
exportToXML(wb);
|
||||||
|
|
||||||
checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(out.toByteArray())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user