Search in sources :

Example 1 with XlsxReadWorkbookHolder

use of com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder in project easyexcel by alibaba.

the class ExcelAnalyserImpl method finish.

@Override
public void finish() {
    if (finished) {
        return;
    }
    finished = true;
    if (analysisContext == null || analysisContext.readWorkbookHolder() == null) {
        return;
    }
    ReadWorkbookHolder readWorkbookHolder = analysisContext.readWorkbookHolder();
    Throwable throwable = null;
    try {
        if (readWorkbookHolder.getReadCache() != null) {
            readWorkbookHolder.getReadCache().destroy();
        }
    } catch (Throwable t) {
        throwable = t;
    }
    try {
        if ((readWorkbookHolder instanceof XlsxReadWorkbookHolder) && ((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();
        }
    } catch (Throwable t) {
        throwable = t;
    }
    // https://github.com/alibaba/easyexcel/issues/2309
    try {
        if ((readWorkbookHolder instanceof CsvReadWorkbookHolder) && ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser() != null) {
            ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser().close();
        }
    } catch (Throwable t) {
        throwable = t;
    }
    try {
        if (analysisContext.readWorkbookHolder().getAutoCloseStream() && readWorkbookHolder.getInputStream() != null) {
            readWorkbookHolder.getInputStream().close();
        }
    } catch (Throwable t) {
        throwable = t;
    }
    try {
        if (readWorkbookHolder.getTempFile() != null) {
            FileUtils.delete(readWorkbookHolder.getTempFile());
        }
    } catch (Throwable t) {
        throwable = t;
    }
    clearEncrypt03();
    removeThreadLocalCache();
    if (throwable != null) {
        throw new ExcelAnalysisException("Can not close IO.", throwable);
    }
}
Also used : CsvReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder) ReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder) XlsxReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder) CsvReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder) XlsReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadWorkbookHolder) XlsReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadWorkbookHolder) XlsxReadWorkbookHolder(com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Aggregations

ExcelAnalysisException (com.alibaba.excel.exception.ExcelAnalysisException)1 ReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder)1 CsvReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder)1 XlsReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.xls.XlsReadWorkbookHolder)1 XlsxReadWorkbookHolder (com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder)1