From 6a3f09905c4b82464900c701ddb60d7bdcde1973 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 9 Feb 2023 18:44:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E7=94=A8=E6=88=B7=E4=B8=8D?= =?UTF-8?q?=E8=B0=83=E7=94=A8finish?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/alibaba/excel/ExcelReader.java | 16 ++++++++++++++++ .../main/java/com/alibaba/excel/ExcelWriter.java | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/ExcelReader.java b/easyexcel-core/src/main/java/com/alibaba/excel/ExcelReader.java index 9508d941..83b46f40 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/ExcelReader.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/ExcelReader.java @@ -11,11 +11,14 @@ import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadWorkbook; +import lombok.extern.slf4j.Slf4j; + /** * Excel readers are all read in event mode. * * @author jipengfei */ +@Slf4j public class ExcelReader implements Closeable { /** @@ -104,4 +107,17 @@ public class ExcelReader implements Closeable { public void close() { finish(); } + + /** + * Prevents calls to {@link #finish} from freeing the cache + * + */ + @Override + protected void finalize() { + try { + finish(); + } catch (Throwable e) { + log.warn("Destroy object failed", e); + } + } } diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/ExcelWriter.java b/easyexcel-core/src/main/java/com/alibaba/excel/ExcelWriter.java index 95d5446b..3c074384 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/ExcelWriter.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/ExcelWriter.java @@ -12,6 +12,8 @@ import com.alibaba.excel.write.metadata.WriteTable; import com.alibaba.excel.write.metadata.WriteWorkbook; import com.alibaba.excel.write.metadata.fill.FillConfig; +import lombok.extern.slf4j.Slf4j; + /** * Excel Writer This tool is used to write value out to Excel via POI. This object can perform the following two * functions. @@ -23,6 +25,7 @@ import com.alibaba.excel.write.metadata.fill.FillConfig; * * @author jipengfei */ +@Slf4j public class ExcelWriter implements Closeable { private final ExcelBuilder excelBuilder; @@ -154,4 +157,16 @@ public class ExcelWriter implements Closeable { public void close() { finish(); } + + /** + * Prevents calls to {@link #finish} from freeing the cache + */ + @Override + protected void finalize() { + try { + finish(); + } catch (Throwable e) { + log.warn("Destroy object failed", e); + } + } }