public class CsvBaseReader extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected static Charset |
DEFAULT_CHARSET
默认编码
|
Constructor and Description |
---|
CsvBaseReader()
构造,使用默认配置项
|
CsvBaseReader(CsvReadConfig config)
构造
|
Modifier and Type | Method and Description |
---|---|
protected CsvParser |
parse(Reader reader)
构建
CsvParser |
CsvData |
read(File file)
读取CSV文件,默认UTF-8编码
|
CsvData |
read(File file,
Charset charset)
读取CSV文件
|
CsvData |
read(Path path)
读取CSV文件,默认UTF-8编码
|
CsvData |
read(Path path,
Charset charset)
读取CSV文件
|
CsvData |
read(Reader reader)
从Reader中读取CSV数据,读取后关闭Reader
|
CsvData |
read(Reader reader,
boolean close)
从Reader中读取CSV数据
|
void |
read(Reader reader,
boolean close,
CsvRowHandler rowHandler)
从Reader中读取CSV数据,读取后关闭Reader
|
<T> List<T> |
read(Reader reader,
Class<T> clazz)
从Reader中读取CSV数据并转换为Bean列表,读取后关闭Reader。
|
void |
read(Reader reader,
CsvRowHandler rowHandler)
从Reader中读取CSV数据,读取后关闭Reader
|
<T> List<T> |
read(String csvStr,
Class<T> clazz)
从字符串中读取CSV数据并转换为Bean列表,读取后关闭Reader。
|
CsvData |
readFromStr(String csvStr)
从字符串中读取CSV数据
|
void |
readFromStr(String csvStr,
CsvRowHandler rowHandler)
从字符串中读取CSV数据
|
List<Map<String,String>> |
readMapList(Reader reader)
从Reader中读取CSV数据,结果为Map,读取后关闭Reader。
|
void |
setContainsHeader(boolean containsHeader)
设置是否首行做为标题行,默认false
|
void |
setErrorOnDifferentFieldCount(boolean errorOnDifferentFieldCount)
设置每行字段个数不同时是否抛出异常,默认false
|
void |
setFieldSeparator(char fieldSeparator)
设置字段分隔符,默认逗号','
|
void |
setSkipEmptyRows(boolean skipEmptyRows)
设置是否跳过空白行,默认true
|
void |
setTextDelimiter(char textDelimiter)
设置 文本分隔符,文本包装符,默认双引号'"'
|
protected static final Charset DEFAULT_CHARSET
public CsvBaseReader()
public CsvBaseReader(CsvReadConfig config)
config
- 配置项public void setFieldSeparator(char fieldSeparator)
fieldSeparator
- 字段分隔符,默认逗号','public void setTextDelimiter(char textDelimiter)
textDelimiter
- 文本分隔符,文本包装符,默认双引号'"'public void setContainsHeader(boolean containsHeader)
containsHeader
- 是否首行做为标题行,默认falsepublic void setSkipEmptyRows(boolean skipEmptyRows)
skipEmptyRows
- 是否跳过空白行,默认truepublic void setErrorOnDifferentFieldCount(boolean errorOnDifferentFieldCount)
errorOnDifferentFieldCount
- 每行字段个数不同时是否抛出异常,默认falsepublic CsvData read(File file) throws IORuntimeException
file
- CSV文件CsvData
,包含数据列表和行信息IORuntimeException
- IO异常public CsvData readFromStr(String csvStr)
csvStr
- CSV字符串CsvData
,包含数据列表和行信息public void readFromStr(String csvStr, CsvRowHandler rowHandler)
csvStr
- CSV字符串rowHandler
- 行处理器,用于一行一行的处理数据public CsvData read(File file, Charset charset) throws IORuntimeException
file
- CSV文件charset
- 文件编码,默认系统编码CsvData
,包含数据列表和行信息IORuntimeException
- IO异常public CsvData read(Path path) throws IORuntimeException
path
- CSV文件CsvData
,包含数据列表和行信息IORuntimeException
- IO异常public CsvData read(Path path, Charset charset) throws IORuntimeException
path
- CSV文件charset
- 文件编码,默认系统编码CsvData
,包含数据列表和行信息IORuntimeException
- IO异常public CsvData read(Reader reader) throws IORuntimeException
reader
- ReaderCsvData
,包含数据列表和行信息IORuntimeException
- IO异常public CsvData read(Reader reader, boolean close) throws IORuntimeException
reader
- Readerclose
- 读取结束是否关闭ReaderCsvData
,包含数据列表和行信息IORuntimeException
- IO异常public List<Map<String,String>> readMapList(Reader reader) throws IORuntimeException
reader
- ReaderCsvData
,包含数据列表和行信息IORuntimeException
- IO异常public <T> List<T> read(Reader reader, Class<T> clazz)
T
- Bean类型reader
- Readerclazz
- Bean类型public <T> List<T> read(String csvStr, Class<T> clazz)
T
- Bean类型csvStr
- csv字符串clazz
- Bean类型public void read(Reader reader, CsvRowHandler rowHandler) throws IORuntimeException
reader
- ReaderrowHandler
- 行处理器,用于一行一行的处理数据IORuntimeException
- IO异常public void read(Reader reader, boolean close, CsvRowHandler rowHandler) throws IORuntimeException
reader
- Readerclose
- 读取结束是否关闭ReaderrowHandler
- 行处理器,用于一行一行的处理数据IORuntimeException
- IO异常protected CsvParser parse(Reader reader) throws IORuntimeException
CsvParser
reader
- ReaderIORuntimeException
- IO异常Copyright © 2024. All rights reserved.