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
This commit is contained in:
Dominik Stadler 2019-05-20 14:42:39 +00:00
parent b2130769b6
commit 1a3e69fe16
2 changed files with 7 additions and 1 deletions

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

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;
}
}