Search in sources :

Example 1 with OLE2NotOfficeXmlFileException

use of org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException in project poi by apache.

the class XSSFFileHandler method handleAdditional.

@SuppressWarnings("resource")
@Override
public void handleAdditional(File file) throws Exception {
    // redirect stdout as the examples often write lots of text
    PrintStream oldOut = System.out;
    try {
        System.setOut(new NullPrintStream());
        FromHowTo.main(new String[] { file.getAbsolutePath() });
        XLSX2CSV.main(new String[] { file.getAbsolutePath() });
        assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!", EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
    } catch (OLE2NotOfficeXmlFileException e) {
    // we have some files that are not actually OOXML and thus cannot be tested here
    } catch (IllegalArgumentException e) {
        if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
            throw e;
        }
    } catch (InvalidFormatException e) {
        if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
            throw e;
        }
    } catch (IOException e) {
        if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
            throw e;
        }
    } catch (POIXMLException e) {
        if (!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
            throw e;
        }
    } finally {
        System.setOut(oldOut);
    }
}
Also used : PrintStream(java.io.PrintStream) OLE2NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException) IOException(java.io.IOException) POIXMLException(org.apache.poi.POIXMLException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException)

Aggregations

IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 POIXMLException (org.apache.poi.POIXMLException)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 OLE2NotOfficeXmlFileException (org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException)1