當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。