From d918c4086081d6c226aeacb9a01caca88cc1428f Mon Sep 17 00:00:00 2001 From: gongxuanzhang Date: Tue, 11 Apr 2023 10:27:57 +0800 Subject: [PATCH] fix bug:input stream auto close when csv builder set autoClose is false --- .../excel/analysis/ExcelAnalyserImpl.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java index 05d4fa84..f8f34d90 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java @@ -1,8 +1,5 @@ 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.v03.XlsSaxAnalyser; 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.NumberDataFormatterUtils; import com.alibaba.excel.util.StringUtils; - import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.crypt.Decryptor; @@ -36,6 +32,9 @@ import org.apache.poi.util.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.InputStream; +import java.util.List; + /** * @author jipengfei */ @@ -158,16 +157,16 @@ public class ExcelAnalyserImpl implements ExcelAnalyser { } try { if ((readWorkbookHolder instanceof XlsxReadWorkbookHolder) - && ((XlsxReadWorkbookHolder)readWorkbookHolder).getOpcPackage() != null) { - ((XlsxReadWorkbookHolder)readWorkbookHolder).getOpcPackage().revert(); + && ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage() != null) { + ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage().revert(); } } catch (Throwable t) { throwable = t; } try { if ((readWorkbookHolder instanceof XlsReadWorkbookHolder) - && ((XlsReadWorkbookHolder)readWorkbookHolder).getPoifsFileSystem() != null) { - ((XlsReadWorkbookHolder)readWorkbookHolder).getPoifsFileSystem().close(); + && ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem() != null) { + ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem().close(); } } catch (Throwable t) { throwable = t; @@ -177,8 +176,9 @@ public class ExcelAnalyserImpl implements ExcelAnalyser { // https://github.com/alibaba/easyexcel/issues/2309 try { if ((readWorkbookHolder instanceof CsvReadWorkbookHolder) - && ((CsvReadWorkbookHolder)readWorkbookHolder).getCsvParser() != null) { - ((CsvReadWorkbookHolder)readWorkbookHolder).getCsvParser().close(); + && ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser() != null + && analysisContext.readWorkbookHolder().getAutoCloseStream()) { + ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser().close(); } } catch (Throwable t) { throwable = t;