Browse Source

fix bug:input stream auto close when csv builder set autoClose is false

pull/3102/head
gongxuanzhang 2 years ago
parent
commit
d918c40860
  1. 20
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java

20
easyexcel-core/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java

@ -1,8 +1,5 @@
package com.alibaba.excel.analysis; package com.alibaba.excel.analysis;
import java.io.InputStream;
import java.util.List;
import com.alibaba.excel.analysis.csv.CsvExcelReadExecutor; import com.alibaba.excel.analysis.csv.CsvExcelReadExecutor;
import com.alibaba.excel.analysis.v03.XlsSaxAnalyser; import com.alibaba.excel.analysis.v03.XlsSaxAnalyser;
import com.alibaba.excel.analysis.v07.XlsxSaxAnalyser; import com.alibaba.excel.analysis.v07.XlsxSaxAnalyser;
@ -26,7 +23,6 @@ import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.FileUtils; import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.util.NumberDataFormatterUtils; import com.alibaba.excel.util.NumberDataFormatterUtils;
import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.StringUtils;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.Decryptor;
@ -36,6 +32,9 @@ import org.apache.poi.util.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.util.List;
/** /**
* @author jipengfei * @author jipengfei
*/ */
@ -158,16 +157,16 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
} }
try { try {
if ((readWorkbookHolder instanceof XlsxReadWorkbookHolder) if ((readWorkbookHolder instanceof XlsxReadWorkbookHolder)
&& ((XlsxReadWorkbookHolder)readWorkbookHolder).getOpcPackage() != null) { && ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage() != null) {
((XlsxReadWorkbookHolder)readWorkbookHolder).getOpcPackage().revert(); ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage().revert();
} }
} catch (Throwable t) { } catch (Throwable t) {
throwable = t; throwable = t;
} }
try { try {
if ((readWorkbookHolder instanceof XlsReadWorkbookHolder) if ((readWorkbookHolder instanceof XlsReadWorkbookHolder)
&& ((XlsReadWorkbookHolder)readWorkbookHolder).getPoifsFileSystem() != null) { && ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem() != null) {
((XlsReadWorkbookHolder)readWorkbookHolder).getPoifsFileSystem().close(); ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem().close();
} }
} catch (Throwable t) { } catch (Throwable t) {
throwable = t; throwable = t;
@ -177,8 +176,9 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
// https://github.com/alibaba/easyexcel/issues/2309 // https://github.com/alibaba/easyexcel/issues/2309
try { try {
if ((readWorkbookHolder instanceof CsvReadWorkbookHolder) if ((readWorkbookHolder instanceof CsvReadWorkbookHolder)
&& ((CsvReadWorkbookHolder)readWorkbookHolder).getCsvParser() != null) { && ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser() != null
((CsvReadWorkbookHolder)readWorkbookHolder).getCsvParser().close(); && analysisContext.readWorkbookHolder().getAutoCloseStream()) {
((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser().close();
} }
} catch (Throwable t) { } catch (Throwable t) {
throwable = t; throwable = t;

Loading…
Cancel
Save