deprecate methods

This commit is contained in:
Looly 2020-08-07 18:09:42 +08:00
parent 594fc16960
commit e0508b0b88
3 changed files with 80 additions and 19 deletions

View File

@ -15,6 +15,7 @@
* 【core 】 ArrayUtil增加isAllNull方法issue#1004@Github
* 【core 】 CollUtil增加contains方法pr#152@Gitee
* 【core 】 ArrayUtil增加isAllNotNull方法pr#1008@Github
* 【poi 】 closeAfterRead参数无效方法设为过期issue#1007@Github
### Bug修复#
* 【core 】 修复原始类型转换时,转换失败没有抛出异常的问题

View File

@ -87,9 +87,21 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
* @param bookStream Excel文件的流
* @param sheetIndex sheet序号0表示第一个sheet
* @param closeAfterRead 读取结束是否关闭流
* @deprecated 使用完毕无论是否closeAfterReadpoi会关闭流此参数无意义
*/
@Deprecated
public ExcelReader(InputStream bookStream, int sheetIndex, boolean closeAfterRead) {
this(WorkbookUtil.createBook(bookStream, closeAfterRead), sheetIndex);
this(WorkbookUtil.createBook(bookStream), sheetIndex);
}
/**
* 构造
*
* @param bookStream Excel文件的流
* @param sheetIndex sheet序号0表示第一个sheet
*/
public ExcelReader(InputStream bookStream, int sheetIndex) {
this(WorkbookUtil.createBook(bookStream), sheetIndex);
}
/**
@ -98,9 +110,21 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
* @param bookStream Excel文件的流
* @param sheetName sheet名第一个默认是sheet1
* @param closeAfterRead 读取结束是否关闭流
* @deprecated 使用完毕无论是否closeAfterReadpoi会关闭流此参数无意义
*/
@Deprecated
public ExcelReader(InputStream bookStream, String sheetName, boolean closeAfterRead) {
this(WorkbookUtil.createBook(bookStream, closeAfterRead), sheetName);
this(WorkbookUtil.createBook(bookStream), sheetName);
}
/**
* 构造
*
* @param bookStream Excel文件的流
* @param sheetName sheet名第一个默认是sheet1
*/
public ExcelReader(InputStream bookStream, String sheetName) {
this(WorkbookUtil.createBook(bookStream), sheetName);
}
/**
@ -398,7 +422,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
final List<T> beanList = new ArrayList<>(mapList.size());
for (Map<String, Object> map : mapList) {
beanList.add(BeanUtil.mapToBean(map, beanType, false));
beanList.add(BeanUtil.toBean(map, beanType));
}
return beanList;
}

View File

@ -1,22 +1,21 @@
package cn.hutool.poi.excel;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.exceptions.POIException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Excel工作簿{@link Workbook}相关工具类
@ -94,9 +93,20 @@ public class WorkbookUtil {
* @param in Excel输入流
* @param closeAfterRead 读取结束是否关闭流
* @return {@link Workbook}
* @deprecated 使用完毕无论是否closeAfterReadpoi会关闭流此参数无意义请使用{@link #createBook(InputStream)}
*/
public static Workbook createBook(InputStream in, boolean closeAfterRead) {
return createBook(in, null, closeAfterRead);
return createBook(in, null);
}
/**
* 创建或加载工作簿
*
* @param in Excel输入流
* @return {@link Workbook}
*/
public static Workbook createBook(InputStream in) {
return createBook(in, null);
}
/**
@ -107,16 +117,28 @@ public class WorkbookUtil {
* @param closeAfterRead 读取结束是否关闭流
* @return {@link Workbook}
* @since 4.0.3
* @deprecated 使用完毕无论是否closeAfterReadpoi会关闭流此参数无意义请使用{@link #createBook(InputStream, String)}
*/
@Deprecated
public static Workbook createBook(InputStream in, String password, boolean closeAfterRead) {
return createBook(in, password);
}
/**
* 创建或加载工作簿
*
* @param in Excel输入流使用完毕自动关闭流
* @param password 密码
* @return {@link Workbook}
* @since 4.0.3
*/
public static Workbook createBook(InputStream in, String password) {
try {
return WorkbookFactory.create(IoUtil.toMarkSupportStream(in), password);
} catch (Exception e) {
throw new POIException(e);
} finally {
if (closeAfterRead) {
IoUtil.close(in);
}
} finally{
IoUtil.close(in);
}
}
@ -191,11 +213,25 @@ public class WorkbookUtil {
* @param closeAfterRead 读取结束是否关闭流
* @return {@link SXSSFWorkbook}
* @since 4.1.13
* @deprecated 使用完毕无论是否closeAfterReadpoi会关闭流此参数无意义请使用{@link #createSXSSFBook(InputStream, String)}
*/
@Deprecated
public static SXSSFWorkbook createSXSSFBook(InputStream in, String password, boolean closeAfterRead) {
return toSXSSFBook(createBook(in, password, closeAfterRead));
}
/**
* 创建或加载SXSSFWorkbook工作簿
*
* @param in Excel输入流
* @param password 密码
* @return {@link SXSSFWorkbook}
* @since 4.1.13
*/
public static SXSSFWorkbook createSXSSFBook(InputStream in, String password) {
return toSXSSFBook(createBook(in, password));
}
/**
* 创建SXSSFWorkbook用于大批量数据写出
*