问题
I was trying to load an excel into POI workbook in a Flink program. Has an error like this.
Caused by: java.lang.IllegalArgumentException: InputStream of class class org.apache.commons.compress.archivers.zip.ZipFile$1 is not implementing InputStreamStatistics. at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.(ZipArchiveThresholdInputStream.java:63) at org.apache.poi.openxml4j.util.ZipSecureFile.getInputStream(ZipSecureFile.java:147) at org.apache.poi.openxml4j.util.ZipSecureFile.getInputStream(ZipSecureFile.java:34) at org.apache.poi.openxml4j.util.ZipFileZipEntrySource.getInputStream(ZipFileZipEntrySource.java:66) at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:258) at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:181) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:323)
notice a test https://github.com/apache/poi/blob/f509d1deae86866ed531f10f2eba7db17e098473/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java here that mention this. But how to work around it. Thanks!
回答1:
You have to include a newer version of commons-compress and shade it (there ar different plugins in Maven, Gradle, SBT). Alternatively, you can use the HadoopOffice library, which has native Flink support, to read/write Excel files (https://github.com/zuinnote/hadoopoffice/wiki) and it has an example on how to shade the dependency correctly (see https://github.com/ZuInnoTe/hadoopoffice/wiki/Using-Apache-Flink-to-read-write-Excel-documents)
来源:https://stackoverflow.com/questions/52467360/flink-inputstream-of-class-class-org-apache-commons-compress-archivers-zip-zipfi