mirror of https://github.com/apache/poi.git
IntegrationTest - move excludes to file handler
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1793595 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
06eb866034
commit
3388787d2c
|
@ -52,6 +52,7 @@ import org.apache.poi.stress.XSSFBFileHandler;
|
|||
import org.apache.poi.stress.XSSFFileHandler;
|
||||
import org.apache.poi.stress.XWPFFileHandler;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
@ -84,7 +85,6 @@ import org.junit.runners.Parameterized.Parameters;
|
|||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestAllFiles {
|
||||
|
||||
private static final File ROOT_DIR = new File("test-data");
|
||||
|
||||
static final String[] SCAN_EXCLUDES = new String[] { "**/.svn/**", "lost+found" };
|
||||
|
@ -202,15 +202,15 @@ public class TestAllFiles {
|
|||
HANDLERS.put("spreadsheet/test_properties1", new NullFileHandler());
|
||||
}
|
||||
|
||||
private static Set<String> unmodifiableHashSet(String... a) {
|
||||
private static final Set<String> unmodifiableHashSet(String... a) {
|
||||
return Collections.unmodifiableSet(hashSet(a));
|
||||
}
|
||||
private static Set<String> hashSet(String... a) {
|
||||
private static final Set<String> hashSet(String... a) {
|
||||
return new HashSet<String>(Arrays.asList(a));
|
||||
}
|
||||
|
||||
// Old Word Documents where we can at least extract some text
|
||||
private static final Set<String> OLD_FILES = unmodifiableHashSet(
|
||||
private static final Set<String> OLD_FILES_HWPF = unmodifiableHashSet(
|
||||
"document/Bug49933.doc",
|
||||
"document/Bug51944.doc",
|
||||
"document/Word6.doc",
|
||||
|
@ -222,7 +222,9 @@ public class TestAllFiles {
|
|||
"document/Bug60942.doc",
|
||||
"document/Bug60942b.doc",
|
||||
"hpsf/TestMickey.doc",
|
||||
"document/52117.doc"
|
||||
"document/52117.doc",
|
||||
"hpsf/TestInvertedClassID.doc",
|
||||
"hpsf/TestBug52117.doc"
|
||||
);
|
||||
|
||||
private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet(
|
||||
|
@ -320,7 +322,7 @@ public class TestAllFiles {
|
|||
// OPC handler works / XSSF handler fails
|
||||
"spreadsheet/57181.xlsm"
|
||||
);
|
||||
|
||||
|
||||
@Parameters(name="{index}: {0} using {1}")
|
||||
public static Iterable<Object[]> files() {
|
||||
DirectoryScanner scanner = new DirectoryScanner();
|
||||
|
@ -346,7 +348,14 @@ public class TestAllFiles {
|
|||
handler instanceof XWPFFileHandler ||
|
||||
handler instanceof XSLFFileHandler ||
|
||||
handler instanceof XDGFFileHandler) {
|
||||
files.add(new Object[] { file, HANDLERS.get(".ooxml") });
|
||||
files.add(new Object[] { file, new OPCFileHandler() });
|
||||
}
|
||||
|
||||
if (handler instanceof HSSFFileHandler ||
|
||||
handler instanceof HSLFFileHandler ||
|
||||
handler instanceof HWPFFileHandler ||
|
||||
handler instanceof HDGFFileHandler) {
|
||||
files.add(new Object[] { file, new HPSFFileHandler() });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,36 +368,37 @@ public class TestAllFiles {
|
|||
|
||||
@Parameter(value=1)
|
||||
public FileHandler handler;
|
||||
|
||||
|
||||
@Test
|
||||
public void testAllFiles() throws Exception {
|
||||
System.out.println("Reading " + file + " with " + handler.getClass());
|
||||
assertNotNull("Unknown file extension for file: " + file + ": " + getExtension(file), handler);
|
||||
File inputFile = new File(ROOT_DIR, file);
|
||||
|
||||
// special cases where docx-handling breaks, but OPCPackage handling works
|
||||
boolean ignoredOPC = (file.endsWith(".docx") || file.endsWith(".xlsx") ||
|
||||
file.endsWith(".xlsb") || file.endsWith(".pptx")) &&
|
||||
handler instanceof OPCFileHandler;
|
||||
boolean ignoreHPSF = (handler instanceof HPSFFileHandler);
|
||||
|
||||
|
||||
try {
|
||||
InputStream stream = new BufferedInputStream(new FileInputStream(inputFile), 64*1024);
|
||||
try {
|
||||
handler.handleFile(stream);
|
||||
|
||||
handler.handleFile(stream, file);
|
||||
assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!",
|
||||
OLD_FILES.contains(file));
|
||||
OLD_FILES_HWPF.contains(file) && !ignoreHPSF);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
handler.handleExtracting(inputFile);
|
||||
|
||||
// special cases where docx-handling breaks, but OPCPackage handling works
|
||||
boolean ignoredOPC = (file.endsWith(".docx") || file.endsWith(".xlsx") ||
|
||||
file.endsWith(".xlsb") || file.endsWith(".pptx")) &&
|
||||
handler instanceof OPCFileHandler;
|
||||
|
||||
assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!",
|
||||
EXPECTED_FAILURES.contains(file) && !ignoredOPC);
|
||||
EXPECTED_FAILURES.contains(file) && !ignoredOPC && !ignoreHPSF);
|
||||
} catch (OldFileFormatException e) {
|
||||
// for old word files we should still support extracting text
|
||||
if(OLD_FILES.contains(file)) {
|
||||
if(OLD_FILES_HWPF.contains(file)) {
|
||||
handler.handleExtracting(inputFile);
|
||||
} else {
|
||||
// check if we expect failure for this file
|
||||
|
@ -397,6 +407,8 @@ public class TestAllFiles {
|
|||
throw new Exception("While handling " + file, e);
|
||||
}
|
||||
}
|
||||
} catch (AssumptionViolatedException e) {
|
||||
// file handler ignored this file
|
||||
} catch (Exception e) {
|
||||
// check if we expect failure for this file
|
||||
if(!EXPECTED_FAILURES.contains(file) && !AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.contains(file)) {
|
||||
|
@ -420,7 +432,7 @@ public class TestAllFiles {
|
|||
|
||||
private static class NullFileHandler implements FileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,9 +32,10 @@ public interface FileHandler {
|
|||
* Closing is handled by the framework outside this call.
|
||||
*
|
||||
* @param stream The input stream to read the file from.
|
||||
* @param path the relative path to the file
|
||||
* @throws Exception If an error happens in the file-specific handler
|
||||
*/
|
||||
void handleFile(InputStream stream) throws Exception;
|
||||
void handleFile(InputStream stream, String path) throws Exception;
|
||||
|
||||
/**
|
||||
* Ensures that extracting text from the given file
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.junit.Test;
|
|||
|
||||
public class HDGFFileHandler extends POIFSFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws IOException {
|
||||
public void handleFile(InputStream stream, String path) throws IOException {
|
||||
POIFSFileSystem poifs = new POIFSFileSystem(stream);
|
||||
HDGFDiagram diagram = new HDGFDiagram(poifs);
|
||||
Stream[] topLevelStreams = diagram.getTopLevelStreams();
|
||||
|
@ -55,11 +55,11 @@ public class HDGFFileHandler extends POIFSFileHandler {
|
|||
@Override
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/diagram/44501.vsd");
|
||||
File file = new File("test-data/diagram/44501.vsd");
|
||||
|
||||
InputStream stream = new FileInputStream(file);
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
|||
public class HMEFFileHandler extends AbstractFileHandler {
|
||||
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
HMEFMessage msg = new HMEFMessage(stream);
|
||||
|
||||
// list all properties
|
||||
|
@ -50,9 +50,10 @@ public class HMEFFileHandler extends AbstractFileHandler {
|
|||
// a test-case to test this locally without executing the full TestAllFiles
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
InputStream stream = new FileInputStream("test-data/hmef/quick-winmail.dat");
|
||||
String path = "test-data/hmef/quick-winmail.dat";
|
||||
InputStream stream = new FileInputStream(path);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, path);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -29,24 +29,25 @@ import org.junit.Test;
|
|||
|
||||
public class HPBFFileHandler extends POIFSFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
HPBFDocument pub = new HPBFDocument(new POIFSFileSystem(stream));
|
||||
assertNotNull(pub.getEscherDelayStm());
|
||||
assertNotNull(pub.getMainContents());
|
||||
assertNotNull(pub.getQuillContents());
|
||||
|
||||
// writing is not yet implemented... handlePOIDocument(pub);
|
||||
pub.close();
|
||||
}
|
||||
|
||||
// a test-case to test this locally without executing the full TestAllFiles
|
||||
@Override
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/publisher/SampleBrochure.pub");
|
||||
File file = new File("test-data/publisher/SampleBrochure.pub");
|
||||
|
||||
InputStream stream = new FileInputStream(file);
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
|
||||
public class HSLFFileHandler extends SlideShowHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
HSLFSlideShowImpl slide = new HSLFSlideShowImpl(stream);
|
||||
assertNotNull(slide.getCurrentUserAtom());
|
||||
assertNotNull(slide.getEmbeddedObjects());
|
||||
|
@ -40,13 +40,13 @@ public class HSLFFileHandler extends SlideShowHandler {
|
|||
assertNotNull("Found a record which was null", record);
|
||||
assertTrue(record.getRecordType() >= 0);
|
||||
}
|
||||
|
||||
|
||||
handlePOIDocument(slide);
|
||||
|
||||
|
||||
HSLFSlideShow ss = new HSLFSlideShow(slide);
|
||||
handleSlideShow(ss);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOne() throws Exception {
|
||||
testOneFile(new File("test-data/slideshow/54880_chinese.ppt"));
|
||||
|
@ -81,10 +81,10 @@ public class HSLFFileHandler extends SlideShowHandler {
|
|||
//System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
handleExtracting(file);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class HSLFFileHandler extends SlideShowHandler {
|
|||
System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
|
||||
InputStream stream = new FileInputStream(args[0]);
|
||||
try {
|
||||
new HSLFFileHandler().handleFile(stream);
|
||||
new HSLFFileHandler().handleFile(stream, args[0]);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
|||
|
||||
public class HSMFFileHandler extends POIFSFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
MAPIMessage mapi = new MAPIMessage(stream);
|
||||
assertNotNull(mapi.getAttachmentFiles());
|
||||
assertNotNull(mapi.getDisplayBCC());
|
||||
|
@ -60,6 +60,8 @@ public class HSMFFileHandler extends POIFSFileHandler {
|
|||
*/
|
||||
|
||||
// writing is not yet supported... handlePOIDocument(mapi);
|
||||
|
||||
mapi.close();
|
||||
}
|
||||
|
||||
// private void writeToFile(MAPIMessage mapi, File file)
|
||||
|
@ -76,10 +78,10 @@ public class HSMFFileHandler extends POIFSFileHandler {
|
|||
@Override
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/hsmf/logsat.com_signatures_valid.msg");
|
||||
File file = new File("test-data/hsmf/logsat.com_signatures_valid.msg");
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import static org.junit.Assert.assertFalse;
|
|||
public class HSSFFileHandler extends SpreadsheetHandler {
|
||||
private final POIFSFileHandler delegate = new POIFSFileHandler();
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
HSSFWorkbook wb = new HSSFWorkbook(stream);
|
||||
handleWorkbook(wb);
|
||||
|
||||
|
@ -100,14 +100,19 @@ public class HSSFFileHandler extends SpreadsheetHandler {
|
|||
// a test-case to test this locally without executing the full TestAllFiles
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/spreadsheet/49219.xls");
|
||||
|
||||
File file = new File("test-data/spreadsheet/49219.xls");
|
||||
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
handleExtracting(file);
|
||||
}
|
||||
|
||||
// a test-case to test this locally without executing the full TestAllFiles
|
||||
@Test
|
||||
public void testExtractor() throws Exception {
|
||||
handleExtracting(new File("test-data/spreadsheet/BOOK_in_capitals.xls"));
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
|
||||
public class HWPFFileHandler extends POIFSFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
HWPFDocument doc = new HWPFDocument(stream);
|
||||
assertNotNull(doc.getBookmarks());
|
||||
assertNotNull(doc.getCharacterTable());
|
||||
|
@ -41,11 +41,11 @@ public class HWPFFileHandler extends POIFSFileHandler {
|
|||
@Override
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/document/52117.doc");
|
||||
File file = new File("test-data/document/52117.doc");
|
||||
|
||||
InputStream stream = new FileInputStream(file);
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.junit.Test;
|
|||
|
||||
public class OPCFileHandler extends AbstractFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
// ignore password protected files
|
||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
|
||||
|
||||
|
@ -63,11 +63,11 @@ public class OPCFileHandler extends AbstractFileHandler {
|
|||
// a test-case to test this locally without executing the full TestAllFiles
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/diagram/test.vsdx");
|
||||
File file = new File("test-data/diagram/test.vsdx");
|
||||
|
||||
InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
|
||||
InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.junit.Test;
|
|||
public class POIFSFileHandler extends AbstractFileHandler {
|
||||
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
POIFSFileSystem fs = new POIFSFileSystem(stream);
|
||||
try {
|
||||
handlePOIFSFileSystem(fs);
|
||||
|
@ -80,7 +80,7 @@ public class POIFSFileHandler extends AbstractFileHandler {
|
|||
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.junit.Test;
|
|||
|
||||
public class XDGFFileHandler extends AbstractFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
// ignore password protected files
|
||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.junit.Test;
|
|||
|
||||
public class XSLFFileHandler extends SlideShowHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
XMLSlideShow slide = new XMLSlideShow(stream);
|
||||
XSLFSlideShow slideInner = new XSLFSlideShow(slide.getPackage());
|
||||
assertNotNull(slideInner.getPresentation());
|
||||
|
@ -69,14 +69,14 @@ public class XSLFFileHandler extends SlideShowHandler {
|
|||
@Override
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/slideshow/ae.ac.uaeu.faculty_nafaachbili_GeomLec1.pptx");
|
||||
InputStream stream = new FileInputStream(file);
|
||||
File file = new File("test-data/slideshow/ae.ac.uaeu.faculty_nafaachbili_GeomLec1.pptx");
|
||||
InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
handleExtracting(file);
|
||||
}
|
||||
}
|
||||
handleExtracting(file);
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ public class XSSFBFileHandler extends AbstractFileHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IOUtils.copy(stream, out);
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class XSSFBFileHandler extends AbstractFileHandler {
|
|||
|
||||
private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException {
|
||||
try {
|
||||
new XSSFWorkbook(pkg);
|
||||
new XSSFWorkbook(pkg).close();
|
||||
} catch (XLSBUnsupportedException e) {
|
||||
//this is what we'd expect
|
||||
//swallow
|
||||
|
|
|
@ -16,6 +16,26 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.stress;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.apache.poi.POIXMLException;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
|
||||
|
@ -31,20 +51,9 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.io.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class XSSFFileHandler extends SpreadsheetHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
// ignore password protected files
|
||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
|
||||
|
||||
|
@ -52,13 +61,13 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
|||
|
||||
// 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();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
IOUtils.copy(stream, out);
|
||||
final byte[] bytes = out.toByteArray();
|
||||
|
||||
checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(bytes)));
|
||||
checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(bytes)));
|
||||
|
||||
wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
|
||||
wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
|
||||
}
|
||||
|
||||
// use the combined handler for HSSF/XSSF
|
||||
|
@ -76,6 +85,8 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
|||
|
||||
// this allows to trigger a heap-dump at this point to see which memory is still allocated
|
||||
//HeapDump.dumpHeap("/tmp/poi.hprof", false);
|
||||
|
||||
wb.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -185,7 +196,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
|||
|
||||
InputStream stream = new BufferedInputStream(new FileInputStream(file));
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.junit.Test;
|
|||
|
||||
public class XWPFFileHandler extends AbstractFileHandler {
|
||||
@Override
|
||||
public void handleFile(InputStream stream) throws Exception {
|
||||
public void handleFile(InputStream stream, String path) throws Exception {
|
||||
// ignore password protected files
|
||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
|
||||
|
||||
|
@ -38,11 +38,11 @@ public class XWPFFileHandler extends AbstractFileHandler {
|
|||
// a test-case to test this locally without executing the full TestAllFiles
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = new File("test-data/document/51921-Word-Crash067.docx");
|
||||
File file = new File("test-data/document/51921-Word-Crash067.docx");
|
||||
|
||||
InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
|
||||
InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
|
||||
try {
|
||||
handleFile(stream);
|
||||
handleFile(stream, file.getPath());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue