本文整理汇总了Java中com.univocity.parsers.csv.CsvParserSettings类的典型用法代码示例。如果您正苦于以下问题:Java CsvParserSettings类的具体用法?Java CsvParserSettings怎么用?Java CsvParserSettings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CsvParserSettings类属于com.univocity.parsers.csv包,在下文中一共展示了CsvParserSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: everyGenderFemale
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Test
public void everyGenderFemale() {
String result = generateAnnotatedPersonCsv();
CsvParser csvParser = new CsvParser(new CsvParserSettings());
boolean firstRow = true;
for (String[] row : csvParser.iterate(new StringReader(result))) {
if (firstRow) {
firstRow = false;
continue;
}
if (!row[2].equals("Female")) {
fail("Gender column is not female! Result: " + row[2]);
}
}
}
示例2: everyNameInList
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Test
public void everyNameInList() {
String result = generateAnnotatedPersonCsv();
CsvParser csvParser = new CsvParser(new CsvParserSettings());
List<String> names = AnnotatedPerson.NameGenerator.getNames();
boolean firstRow = true;
for (String[] row : csvParser.iterate(new StringReader(result))) {
if (firstRow) {
firstRow = false;
continue;
}
if (!names.contains(row[0])) {
fail("Name column value is not in list! Result: '" + row[0] + " 'List: " + names);
}
}
}
示例3: agesInRange
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Test
public void agesInRange() {
String result = generateAnnotatedPersonCsv();
CsvParser csvParser = new CsvParser(new CsvParserSettings());
boolean firstRow = true;
for (String[] row : csvParser.iterate(new StringReader(result))) {
if (firstRow) {
firstRow = false;
continue;
}
int age = Integer.parseInt(row[1]);
assertTrue(age + "",age <= maxAge);
assertTrue(age + "",age >= minAge);
}
}
示例4: parse
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
private DataFrame<R,String> parse(Sheet sheet) {
DataFormatter formatter = new DataFormatter();
int rowIndex = 0;
for(Iterator<Row> rowIter = sheet.rowIterator(); rowIter.hasNext();){
Row excelRow = rowIter.next();
if( rowIndex ==0){
if( this.output == null ){
this.output = new ParserOutput(new CsvParserSettings());
}
}
final int numberOfColumns = excelRow.getLastCellNum();
String[] row = new String[numberOfColumns];
for(int i = 0; i < numberOfColumns; i++){
Cell cell = excelRow.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
row[i] = formatter.formatCellValue(cell);
}
endRow( row, rowIndex );
rowIndex++;
}
endProcess();
return this.frame;
}
示例5: parse
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
/**
* Returns a DataFrame parsed from the stream specified stream
* @param stream the stream to parse
* @return the DataFrame parsed from stream
* @throws IOException if there stream read error
*/
private DataFrame<R,String> parse(CsvSourceOptions<R> options, InputStream stream) throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, options.getCharset().orElse(StandardCharsets.UTF_8)))) {
final CsvRequestHandler handler = new CsvRequestHandler(options);
final CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setDelimiter(options.getDelimiter());
settings.setHeaderExtractionEnabled(options.isHeader());
settings.setLineSeparatorDetectionEnabled(true);
settings.setRowProcessor(handler);
settings.setIgnoreTrailingWhitespaces(true);
settings.setIgnoreLeadingWhitespaces(true);
settings.setMaxColumns(10000);
settings.setReadInputOnSeparateThread(false);
final CsvParser parser = new CsvParser(settings);
parser.parse(reader);
return handler.getFrame();
}
}
示例6: parseIssues
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
/**
* Method to start parsing issues from the provided input stream.
*
* @param inputStream
* stream that contains uploaded BlackDuck scan result file data.
* @param beanProcessor
* BeanProcessor implementation that is responsible for fetching vulnerabilities from the
* rows of the provided black duck result CSV file.
* @throws ScanParsingException
* @throws IOException
* If an I/O error occurs during CSV file processing.
* @throws IllegalArgumentException
* if inputStream and / or beanProcessor are null.
*/
public void parseIssues(final InputStream inputStream, final BeanProcessor<BlackDuckIssue> beanProcessor) throws ScanParsingException, IOException {
LOG.info("Parsing issues for Black Duck");
if (inputStream == null) {
throw new IllegalArgumentException("inputStream cannot be null");
}
if (beanProcessor == null) {
throw new IllegalArgumentException("beanProcessor cannot be null");
}
final CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.setRowProcessor(beanProcessor);
parserSettings.setHeaderExtractionEnabled(true);
try (final InputStreamCsvParser inputStreamCsvParser = new InputStreamCsvParser(parserSettings, inputStream)) {
inputStreamCsvParser.parse();
}
}
示例7: loadZones
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
private void loadZones(ZipInputStream zipis) throws UnsupportedEncodingException{
CsvParserSettings settings = new CsvParserSettings();
settings.setSkipEmptyLines(true);
settings.setNumberOfRowsToSkip(1);
settings.trimValues(true);
CsvFormat format = new CsvFormat();
format.setDelimiter(',');
format.setLineSeparator("\n");
format.setCharToEscapeQuoteEscaping('\0');
format.setQuote('"');
settings.setFormat(format);
CsvParser parser = new CsvParser(settings);
Map<String, TimeZone> idMapRead = new HashMap<>();
List<String[]> lines = parser.parseAll(new InputStreamReader(zipis, "UTF-8"));
for(String[] entry : lines){
TimeZone timeZone = new TimeZone();
timeZone.setId(Integer.parseInt(entry[0]));
timeZone.setCountryIso(entry[1]);
timeZone.setName(entry[2]);
idMapRead.put(timeZone.getName().trim().toUpperCase(), timeZone);
}
this.idMap = idMapRead;
logger.info("loaded "+idMapRead.size()+" time zones");
}
示例8: initialize
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
/**
* Below method will be used to initialize the the parser
*
* @throws IOException
*/
public void initialize() throws IOException {
CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.getFormat().setDelimiter(csvParserVo.getDelimiter().charAt(0));
parserSettings.getFormat().setComment(csvParserVo.getCommentCharacter().charAt(0));
parserSettings.setLineSeparatorDetectionEnabled(true);
parserSettings.setMaxColumns(
getMaxColumnsForParsing(csvParserVo.getNumberOfColumns(), csvParserVo.getMaxColumns()));
parserSettings.setNullValue("");
parserSettings.setIgnoreLeadingWhitespaces(false);
parserSettings.setIgnoreTrailingWhitespaces(false);
parserSettings.setSkipEmptyLines(false);
parserSettings.getFormat().setQuote(null == csvParserVo.getQuoteCharacter() ?
'\"':csvParserVo.getQuoteCharacter().charAt(0));
parserSettings.getFormat().setQuoteEscape(null == csvParserVo.getEscapeCharacter() ?
'\\' :
csvParserVo.getEscapeCharacter().charAt(0));
blockCounter++;
initializeReader();
if (csvParserVo.getBlockDetailsList().get(blockCounter).getBlockOffset() == 0) {
parserSettings.setHeaderExtractionEnabled(csvParserVo.isHeaderPresent());
}
parser = new CsvParser(parserSettings);
parser.beginParsing(inputStreamReader);
}
示例9: mapCsv
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Benchmark
public void mapCsv(Blackhole blackhole, CsvParam csvParam) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
//turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(false);
settings.setRowProcessor(new BeanProcessor<City>(City.class) {
@Override
public void beanProcessed(City bean, ParsingContext context) {
blackhole.consume(bean);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try(Reader reader = csvParam.getReader()) {
parser.parse(reader);
}
}
示例10: parseCsv
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Benchmark
public void parseCsv(Blackhole blackhole, CsvParam csvParam) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
//turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(false);
settings.setRowProcessor(new AbstractRowProcessor() {
@Override
public void rowProcessed(String[] row, ParsingContext context) {
blackhole.consume(row);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try(Reader reader = csvParam.getReader()) {
parser.parse(reader);
}
}
示例11: main
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
CsvParam csvParam = new CsvParam();
csvParam.setUp();
CsvParserSettings settings = new CsvParserSettings();
//turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(false);
settings.setProcessor(new BeanProcessor<City>(City.class) {
@Override
public void beanProcessed(City bean, ParsingContext context) {
System.out.println(bean);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try(Reader reader = csvParam.getReader()) {
parser.parse(reader);
}
}
示例12: parseCsv
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Benchmark
public void parseCsv(Blackhole blackhole) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
//turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(true);
settings.setRowProcessor(new AbstractRowProcessor() {
@Override
public void rowProcessed(String[] row, ParsingContext context) {
blackhole.consume(row);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try(Reader reader = CsvParam.getSingleThreadedReader(quotes, nbRows)) {
parser.parse(reader);
}
}
示例13: mapCsv
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
@Benchmark
public void mapCsv(Blackhole blackhole) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
//turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setRowProcessor(new BeanProcessor<City>(City.class) {
@Override
public void beanProcessed(City bean, ParsingContext context) {
blackhole.consume(bean);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try(Reader reader = CsvParam.getSingleThreadedReader(quotes, nbRows)) {
parser.parse(reader);
}
}
示例14: ListParser
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
public ListParser(Parser inParser, char inCollectionDelim,
char inCollectionBegin, char inCollectionEnd) {
parser = inParser;
collectionDelim = inCollectionDelim;
collectionBegin = inCollectionBegin;
collectionEnd = inCollectionEnd;
elements = new ArrayList<Object>();
CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setLineSeparator("\n");
settings.getFormat().setDelimiter(collectionDelim);
settings.getFormat().setQuote(collectionQuote);
settings.getFormat().setQuoteEscape(collectionEscape);
settings.getFormat().setCharToEscapeQuoteEscaping(collectionEscape);
settings.setKeepQuotes(true);
settings.setKeepEscapeSequences(true);
csvp = new CsvParser(settings);
}
示例15: MapParser
import com.univocity.parsers.csv.CsvParserSettings; //导入依赖的package包/类
public MapParser(Parser inKeyParser, Parser inValueParser,
char inCollectionDelim, char inCollectionBegin,
char inCollectionEnd, char inMapDelim) {
keyParser = inKeyParser;
valueParser = inValueParser;
collectionDelim = inCollectionDelim;
collectionBegin = inCollectionBegin;
collectionEnd = inCollectionEnd;
mapDelim = inMapDelim;
elements = new HashMap<Object,Object>();
CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setLineSeparator("" + collectionDelim);
settings.getFormat().setNormalizedNewline(collectionDelim);
settings.getFormat().setDelimiter(mapDelim);
settings.getFormat().setQuote(collectionQuote);
settings.getFormat().setQuoteEscape(collectionEscape);
settings.getFormat().setCharToEscapeQuoteEscaping(collectionEscape);
settings.setKeepQuotes(true);
settings.setKeepEscapeSequences(true);
csvp = new CsvParser(settings);
}