monitorjbl / excel-streaming-reader

An easy-to-use implementation of a streaming Excel reader using Apache POI
Apache License 2.0
960 stars 345 forks source link

Provider for class javax.xml.stream.XMLInputFactory cannot be created #184

Open mengqingmeng opened 5 years ago

mengqingmeng commented 5 years ago

I read the excel file in a thread like this:

Runnable task = ()->{
            long start = System.currentTimeMillis();
            boolean firstLine = true;
            try(
                    InputStream targetStream = new FileInputStream(tmpFile);
                    Workbook wb = StreamingReader.builder().sstCacheSize(500).open(targetStream);
            ) {

                // 取第一个sheet
                Sheet sheet = wb.getSheetAt(0);
               ....
            } catch (IOException e) {
                log.error("读取excel文件错误:"+file.getOriginalFilename()+";error:"+e.getMessage());
            }
            tmpFile.delete();
        };

        Thread thread = new Thread(task);
        thread.start();

sometimes ,I will get this error,anybody can help me ? 🙏

Exception in thread "Thread-13" javax.xml.stream.FactoryConfigurationError: Provider for class javax.xml.stream.XMLInputFactory cannot be created
        at javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:370)
        at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:313)
        at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:227)
        at javax.xml.stream.XMLInputFactory.newFactory(XMLInputFactory.java:205)
        at org.apache.poi.util.StaxHelper.newXMLInputFactory(StaxHelper.java:37)
        at com.monitorjbl.xlsx.sst.BufferedStringsTable.readFrom(BufferedStringsTable.java:37)
        at com.monitorjbl.xlsx.sst.BufferedStringsTable.<init>(BufferedStringsTable.java:31)
        at com.monitorjbl.xlsx.sst.BufferedStringsTable.getSharedStringsTable(BufferedStringsTable.java:26)
        at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:120)
        at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:91)
        at com.monitorjbl.xlsx.StreamingReader$Builder.open(StreamingReader.java:251)
        at com.hbsmzpc.youshowapi.service.ProductServiceImpl.lambda$uploadBase$2(ProductServiceImpl.java:372)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Provider for class javax.xml.stream.XMLInputFactory cannot be created
        at javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:367)
        ... 12 more
Caused by: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Error reading configuration file
        at java.util.ServiceLoader.fail(ServiceLoader.java:232)
        at java.util.ServiceLoader.parse(ServiceLoader.java:309)
        at java.util.ServiceLoader.access$200(ServiceLoader.java:185)
        at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
        at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
        at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
        at javax.xml.stream.FactoryFinder$1.run(FactoryFinder.java:352)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:341)
        ... 12 more
Caused by: java.util.zip.ZipException: invalid distance too far back
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
        at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:52)
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at java.io.BufferedReader.fill(BufferedReader.java:161)
        at java.io.BufferedReader.readLine(BufferedReader.java:324)
        at java.io.BufferedReader.readLine(BufferedReader.java:389)
        at java.util.ServiceLoader.parseLine(ServiceLoader.java:255)
        at java.util.ServiceLoader.parse(ServiceLoader.java:307)
        ... 19 more
pjfanning commented 5 years ago

The 2 most likely causes are

If you could provide a sample file that produces this issue, could you raise a POI issue at https://bz.apache.org/bugzilla/ ?