diff --git a/CHANGELOG.md b/CHANGELOG.md
index 18249e244..c69bf49a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
### 新特性
* 【core 】 NumberConverter Long类型增加日期转换(pr#872@Github)
* 【all 】 StrUtil and SymmetricCrypto注释修正(pr#873@Github)
+* 【core 】 CsvReader支持返回Bean(issue#869@Github)
### Bug修复
diff --git a/hutool-core/src/main/java/cn/hutool/core/io/resource/ResourceUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/resource/ResourceUtil.java
index bc7e8c47a..b8b9844d1 100644
--- a/hutool-core/src/main/java/cn/hutool/core/io/resource/ResourceUtil.java
+++ b/hutool-core/src/main/java/cn/hutool/core/io/resource/ResourceUtil.java
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.EnumerationIter;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
+import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ClassLoaderUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
@@ -61,41 +62,52 @@ public class ResourceUtil {
/**
* 从ClassPath资源中获取{@link InputStream}
*
- * @param resurce ClassPath资源
+ * @param resource ClassPath资源
* @return {@link InputStream}
* @throws NoResourceException 资源不存在异常
* @since 3.1.2
*/
- public static InputStream getStream(String resurce) throws NoResourceException {
- return getResourceObj(resurce).getStream();
+ public static InputStream getStream(String resource) throws NoResourceException {
+ return getResourceObj(resource).getStream();
}
/**
* 从ClassPath资源中获取{@link InputStream},当资源不存在时返回null
*
- * @param resurce ClassPath资源
+ * @param resource ClassPath资源
* @return {@link InputStream}
* @since 4.0.3
*/
- public static InputStream getStreamSafe(String resurce) {
+ public static InputStream getStreamSafe(String resource) {
try {
- return getResourceObj(resurce).getStream();
+ return getResourceObj(resource).getStream();
} catch (NoResourceException e) {
// ignore
}
return null;
}
+ /**
+ * 从ClassPath资源中获取{@link BufferedReader}
+ *
+ * @param resource ClassPath资源
+ * @return {@link InputStream}
+ * @since 5.3.6
+ */
+ public static BufferedReader getUtf8Reader(String resource) {
+ return getReader(resource, CharsetUtil.CHARSET_UTF_8);
+ }
+
/**
* 从ClassPath资源中获取{@link BufferedReader}
*
- * @param resurce ClassPath资源
+ * @param resource ClassPath资源
* @param charset 编码
* @return {@link InputStream}
* @since 3.1.2
*/
- public static BufferedReader getReader(String resurce, Charset charset) {
- return getResourceObj(resurce).getReader(charset);
+ public static BufferedReader getReader(String resource, Charset charset) {
+ return getResourceObj(resource).getReader(charset);
}
/**
diff --git a/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvBaseReader.java b/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvBaseReader.java
index d65bb56ee..f41987037 100644
--- a/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvBaseReader.java
+++ b/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvBaseReader.java
@@ -14,6 +14,7 @@ import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
/**
@@ -143,17 +144,6 @@ public class CsvBaseReader implements Serializable {
return read(FileUtil.getReader(path, charset));
}
- /**
- * 从Reader中读取CSV数据,读取后关闭Reader
- *
- * @param reader Reader
- * @param rowHandler 行处理器,用于一行一行的处理数据
- * @throws IORuntimeException IO异常
- */
- public void read(Reader reader, CsvRowHandler rowHandler) throws IORuntimeException {
- read(parse(reader), rowHandler);
- }
-
/**
* 从Reader中读取CSV数据,读取后关闭Reader
*
@@ -170,6 +160,52 @@ public class CsvBaseReader implements Serializable {
return new CsvData(header, rows);
}
+ /**
+ * 从Reader中读取CSV数据,结果为Map,读取后关闭Reader。
+ * 此方法默认识别首行为标题行。
+ *
+ * @param reader Reader
+ * @return {@link CsvData},包含数据列表和行信息
+ * @throws IORuntimeException IO异常
+ */
+ public List