Browse Source

防止用户不调用finish

stringcache
Jiaju Zhuang 2 years ago
parent
commit
6a3f09905c
  1. 16
      easyexcel-core/src/main/java/com/alibaba/excel/ExcelReader.java
  2. 15
      easyexcel-core/src/main/java/com/alibaba/excel/ExcelWriter.java

16
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.ReadSheet;
import com.alibaba.excel.read.metadata.ReadWorkbook; import com.alibaba.excel.read.metadata.ReadWorkbook;
import lombok.extern.slf4j.Slf4j;
/** /**
* Excel readers are all read in event mode. * Excel readers are all read in event mode.
* *
* @author jipengfei * @author jipengfei
*/ */
@Slf4j
public class ExcelReader implements Closeable { public class ExcelReader implements Closeable {
/** /**
@ -104,4 +107,17 @@ public class ExcelReader implements Closeable {
public void close() { public void close() {
finish(); 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);
}
}
} }

15
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.WriteWorkbook;
import com.alibaba.excel.write.metadata.fill.FillConfig; 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 * Excel Writer This tool is used to write value out to Excel via POI. This object can perform the following two
* functions. * functions.
@ -23,6 +25,7 @@ import com.alibaba.excel.write.metadata.fill.FillConfig;
* *
* @author jipengfei * @author jipengfei
*/ */
@Slf4j
public class ExcelWriter implements Closeable { public class ExcelWriter implements Closeable {
private final ExcelBuilder excelBuilder; private final ExcelBuilder excelBuilder;
@ -154,4 +157,16 @@ public class ExcelWriter implements Closeable {
public void close() { public void close() {
finish(); 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);
}
}
} }

Loading…
Cancel
Save