com.github.rrsunhome.excelsql.parser.CsvFileParser Maven / Gradle / Ivy
package com.github.rrsunhome.excelsql.parser;
import com.github.rrsunhome.excelsql.config.BaseParserConfig;
import com.github.rrsunhome.excelsql.config.CsvParserConfig;
import com.github.rrsunhome.excelsql.parser.support.ArrayRowResultSet;
import com.github.rrsunhome.excelsql.parser.support.BaseRowResultSet;
import com.github.rrsunhome.excelsql.util.CSVResultSet;
import com.github.rrsunhome.excelsql.util.CSVRowMapper;
import com.github.rrsunhome.excelsql.util.CSVUtils;
import java.io.InputStream;
import java.util.List;
/**
* @author : wangqijia
* create at: 2021/10/27 下午1:47
*/
public class CsvFileParser extends AbstractFileParser {
@Override
public String[] getSupportedFileExtensions() {
return new String[]{"csv"};
}
@Override
public BaseParserConfig getDefaultParserConfig() {
return new CsvParserConfig();
}
@Override
protected List load(InputStream is, BaseParserConfig parserConfig) throws Exception {
return readCsv(is);
}
protected List readCsv(InputStream is) throws Exception {
return CSVUtils.read(is, new CSVRowMapper() {
@Override
public BaseRowResultSet mapRow(CSVResultSet rs, int rowNum) {
return new ArrayRowResultSet(rowNum, rs.getValues());
}
});
}
}