当前位置: 首页>>代码示例>>Java>>正文


Java CSVParser.forEach方法代码示例

本文整理汇总了Java中org.apache.commons.csv.CSVParser.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java CSVParser.forEach方法的具体用法?Java CSVParser.forEach怎么用?Java CSVParser.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.csv.CSVParser的用法示例。


在下文中一共展示了CSVParser.forEach方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadData

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
@Override
public void loadData(List<Tuple<String, File>> files, Importer importer) throws InvalidFileException, IOException {
  for (Tuple<String, File> file : files) {
    CSVParser parser = format.parse(new FileReader(file.getRight()));

    String filename = file.getLeft();
    //remove well-known extensions
    if (filename.endsWith(".csv") || filename.endsWith(".tsv") || filename.endsWith(".txt")) {
      filename = filename.substring(0, filename.length() - 4);
    }
    importer.startCollection(filename);

    parser.getHeaderMap().forEach((name, column) -> importer.registerPropertyName(column, name));

    parser.forEach(row -> {
      importer.startEntity();
      for (int i = 0; i < row.size(); i++) {
        importer.setValue(i, row.get(i));
      }
      importer.finishEntity();
    });

    importer.finishCollection();
  }
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:26,代码来源:CsvLoader.java

示例2: parse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public List<PhotoLocationKeyword> parse() throws IOException{
	CSVParser parser = CSVFormat.RFC4180.withHeader().
			withDelimiter(',')
			.withAllowMissingColumnNames(true)
			.parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	
	List<PhotoLocationKeyword> keywords = new ArrayList<>();		
	parser.forEach((record) -> {
		keywords.add(parseRecord(record));
	});		
	return keywords;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:13,代码来源:PhotoLocationKeywordsParser.java

示例3: getMapFromFromCsvFile

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public Map<String,String> getMapFromFromCsvFile(String filename, CSVFormat csvFormat) throws IOException {
    try(FileReader fileReader = new FileReader(new File(filename))) {
        CSVParser csvParser = new CSVParser(fileReader, csvFormat);
        Map<String,String> map = new HashMap<>();
        csvParser.forEach(record -> map.put(record.get(0), record.get(1)));
        return map;
    } catch (IOException e) {
        logger.error("Failed to open CSV file {} for reading", filename);
        throw e;
    }
}
 
开发者ID:vrk-kpa,项目名称:e-identification-tupas-idp-public,代码行数:12,代码来源:AdapterPropertyMapper.java

示例4: parseFile

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
static void parseFile(final String fileStr, final PublishSubject<Map<String, String>> subject) throws Exception {

        final CSVParser parser = CSVParser.parse(
            new File(fileStr), StandardCharsets.UTF_8, CSVFormat.DEFAULT
        );

        try {
            parser.forEach(csvRecord -> subject.onNext(toMap(csvRecord)));
            subject.onComplete();
        } finally {
            parser.close();
        }
    }
 
开发者ID:codefacts,项目名称:Elastic-Components,代码行数:14,代码来源:ParseCsv.java

示例5: importDatasource

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
    LocalDateTime TIMESTAMP = TimedValueUtils.parseTimestampString("2011");

    // Collect materialised attributes
    List<Attribute> attributes = new ArrayList<>();
    for (Attribute attribute : datasource.getTimedValueAttributes()) {
        attributes.add(AttributeUtils.getByProviderAndLabel(attribute.getProvider(), attribute.getLabel()));
    }

    // Looping through all the subjects provided in the recipe and saving there respective values
    for (SubjectRecipe subjectTypeFromRecipe : subjectRecipes) {
        OaImporter.OaType oaType = OaImporter.OaType.valueOf(subjectTypeFromRecipe.getSubjectType());
        SubjectType subjectType = SubjectTypeUtils.getOrCreate(AbstractONSImporter.PROVIDER,
                oaType.name(), oaType.datasourceSpec.getDescription());

        List<TimedValue> timedValueBuffer = new ArrayList<>();
        String dataUrl = getDataUrl(datasource.getDatasourceSpec().getId(), subjectTypeFromRecipe.getSubjectType());

        InputStream dataStream = downloadUtils.fetchInputStream(
                new URL(dataUrl), getProvider().getLabel(), ".csv");

        CSVParser csvParser = new CSVParser(new InputStreamReader(dataStream),
                CSVFormat.RFC4180.withFirstRecordAsHeader());

        csvParser.forEach(record -> {
            Subject subject = SubjectUtils.getSubjectByTypeAndLabel(subjectType, record.get("geography code"));
            if (subject != null) {
                attributes.forEach(attribute -> {
                    String value = record.get(attribute.getDescription());
                    TimedValue timedValue = new TimedValue(subject, attribute, TIMESTAMP, Double.valueOf(value));
                    timedValueBuffer.add(timedValue);
                });
            }
        });

        saveAndClearTimedValueBuffer(timedValueBuffer);
    }
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:40,代码来源:CensusImporter.java

示例6: readFromCsv

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static ReadResult readFromCsv(InputStream input, Consumer<? super CSVRecord> action) throws IOException {
	BufferedReader reader = new BufferedReader(new InputStreamReader(input, CHARSET), READ_BUFFER_SIZE);
	CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL
		.withDelimiter(';')
		.withRecordSeparator('\n')
	);
	RecordReaderWrapper wrapper = new RecordReaderWrapper(action);
	parser.forEach(wrapper);
	parser.close();
	reader.close();
	return new ReadResult(wrapper.readedReacords, wrapper.successfulReadedRecors);
}
 
开发者ID:progolden,项目名称:vraptor-boilerplate,代码行数:13,代码来源:CsvUtils.java


注:本文中的org.apache.commons.csv.CSVParser.forEach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。