gpt4 book ai didi

java - 'ZipException : invalid code lengths set' when streaming input file to Apache-POI

转载 作者:行者123 更新时间:2023-11-30 02:20:27 26 4
gpt4 key购买 nike

我尝试通过将 .xlsx 作为资源流传递来使用 Apache-POI 创建 xlsx 工作簿对象:

Workbook workbook = WorkbookFactory.create(RFQGenerator.class.getResourceAsStream("/com/lumos/xlsx_manager/es/da/template.xlsx"));

通过 FileInputStream 和本地文件路径传递 template.xlsx 时,我可以成功实例化工作簿,但是当我传递资源流时,出现异常:

java.io.IOException: Failed to read zip entry source
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:103)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:184)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
at com.lumos.xlsx_manager.es.da.RFQGenerator.createRfq(RFQGenerator.java:30)
at com.lumos.xlsx_manager.es.da.Firebase$2.onChildAdded(Firebase.java:88)
at com.google.firebase.database.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:81)
at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:65)
at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.zip.ZipException: invalid code lengths set
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:220)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.<init>(ZipInputStreamZipEntrySource.java:132)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:56)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:100)
... 11 more

我传递的 .xlsx 不应被压缩,但也许这就是它与资源流一起工作的方式。关于如何通过资源访问将文件传递到 Apache-POI 有什么想法吗?

最佳答案

事实证明,使用 Maven 资源时必须取消过滤二进制文件。

Maven corrupting binary files in source/main/resources when building jar

关于java - 'ZipException : invalid code lengths set' when streaming input file to Apache-POI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47011240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com