\r
import java.io.File;\r
import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.util.HashSet;\r
import org.apache.poi.POITextExtractor;\r
import org.apache.poi.extractor.ExtractorFactory;\r
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;\r
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;\r
import org.apache.xmlbeans.XmlException;\r
\r
EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-simple.dat");\r
EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-with-attachments.dat");\r
EXPECTED_EXTRACTOR_FAILURES.add("hpsf/Test0313rur.adm");\r
- EXPECTED_EXTRACTOR_FAILURES.add("hsmf/attachment_msg_pdf.msg");\r
EXPECTED_EXTRACTOR_FAILURES.add("poifs/Notes.ole2");\r
- EXPECTED_EXTRACTOR_FAILURES.add("slideshow/testPPT.thmx");\r
}\r
\r
public void handleExtracting(File file) throws Exception {\r
assertNotNull(metadataExtractor.getText());\r
\r
assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!", \r
- EXPECTED_EXTRACTOR_FAILURES.contains(file));\r
+ EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));\r
\r
assertEquals("File should not be modified by extractor", length, file.length());\r
assertEquals("File should not be modified by extractor", modified, file.lastModified());\r
}\r
}\r
} catch (IllegalArgumentException e) {\r
- if(!EXPECTED_EXTRACTOR_FAILURES.contains(file)) {\r
+ if(!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {\r
throw e;\r
}\r
} finally {\r
}\r
}\r
\r
- private void handleExtractingAsStream(File file) throws FileNotFoundException,\r
- IOException, InvalidFormatException, OpenXML4JException,\r
- XmlException {\r
+ private void handleExtractingAsStream(File file) throws IOException, OpenXML4JException, XmlException {\r
InputStream stream = new FileInputStream(file);\r
try {\r
POITextExtractor streamExtractor = ExtractorFactory.createExtractor(stream);\r
@Override
public void handleFile(InputStream stream) throws Exception {
HSSFWorkbook wb = new HSSFWorkbook(stream);
- handleWorkbook(wb, ".xls");
+ handleWorkbook(wb);
// TODO: some documents fail currently...
//HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.RecordFormatException;
public abstract class SpreadsheetHandler extends AbstractFileHandler {
- public void handleWorkbook(Workbook wb, String extension) throws IOException {
+ public void handleWorkbook(Workbook wb) throws IOException {
// try to access some of the content
readContent(wb);
// write out the file
- ByteArrayOutputStream out = writeToArray(wb);
+ writeToArray(wb);
// access some more content (we had cases where writing corrupts the data in memory)
readContent(wb);
// write once more
- out = writeToArray(wb);
+ ByteArrayOutputStream out = writeToArray(wb);
// read in the writen file
Workbook read;
read.close();
}
- private ByteArrayOutputStream writeToArray(Workbook wb)
- throws FileNotFoundException, IOException {
+ private ByteArrayOutputStream writeToArray(Workbook wb) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
wb.write(stream);
for(Row row : sheet) {
for(Cell cell : row) {
- cell.toString();
+ assertNotNull(cell.toString());
}
}
}
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.IOUtils;
wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
// use the combined handler for HSSF/XSSF
- handleWorkbook(wb, ".xlsx");
+ handleWorkbook(wb);
// TODO: some documents fail currently...
//XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb);
}
- private void checkXSSFReader(OPCPackage p)
- throws IOException, OpenXML4JException, InvalidFormatException {
+ private void checkXSSFReader(OPCPackage p) throws IOException, OpenXML4JException {
XSSFReader reader = new XSSFReader(p);
// these can be null...