Browse Source

Include actual found type in exception when encountering unexpected type of file in ExtractorFactory

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859565 13f79535-47bb-0310-9956-ffa450edef68
pull/139/head
Dominik Stadler 5 years ago
parent
commit
3dbf8df012

+ 1
- 1
src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java View File

@@ -167,7 +167,7 @@ public final class ExtractorFactory {
case OOXML:
return createExtractor(OPCPackage.open(is));
default:
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream, found type: " + fm);
}
}


+ 6
- 0
src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java View File

@@ -42,6 +42,7 @@ import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
@@ -193,6 +194,11 @@ public class TestExtractorFactory {
try (FileInputStream fis = new FileInputStream(txt);
POITextExtractor ignored = poifs.apply(fis)) {
fail("extracting from invalid package");
} catch (IllegalArgumentException e) {
assertTrue("Had: " + e,
e.getMessage().contains(FileMagic.UNKNOWN.name()));

throw e;
}
}


Loading…
Cancel
Save