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


Java CSVRecord类代码示例

本文整理汇总了Java中org.apache.commons.csv.CSVRecord的典型用法代码示例。如果您正苦于以下问题:Java CSVRecord类的具体用法?Java CSVRecord怎么用?Java CSVRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: iterator

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
@Override
public Iterator<String[]> iterator() throws Exception{
    Iterator<CSVRecord> iterCSVRecords = this.getCSVParser().iterator();
    
    Iterator<String[]> iterStringArrays = Iterators.transform(iterCSVRecords, (CSVRecord input) -> {
        Iterator<String> iterCols = input.iterator();
        
        List<String> cols = new ArrayList();
        while(iterCols.hasNext()){
            cols.add(iterCols.next());
        }
        
        String[] output = cols.toArray(new String[0]);
        
        return output;
    });
    
    return iterStringArrays;
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:20,代码来源:CsvDataSource.java

示例2: write

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
@Override
public void write(String outputFilePath) throws Exception{            
   try(Writer out = new BufferedWriter(new FileWriter(outputFilePath));
           CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.RFC4180)) {
        
        if(this.getHeaders() != null){
            csvPrinter.printRecord(this.getHeaders());
        }
        
        Iterator<CSVRecord> recordIter = this.getCSVParser().iterator();
        while(recordIter.hasNext()){
            CSVRecord record = recordIter.next();
            csvPrinter.printRecord(record);
        }
        
        csvPrinter.flush();
            
   }catch(Exception e){
        throw e;
   }
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:22,代码来源:CsvDataSource.java

示例3: parse

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
private ArrayList<Map<String, String>> parse()  {
	final ArrayList<Map<String, String>> list;
	final CSVParser parser;
	final URL resource;
	final CSVFormat csvFormat;
	final Charset charset;
	list = new ArrayList<Map<String, String>> ();
	try {
		resource = ResourceHelper.getResource(isFromGameResourceInput(),fileName);
		charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
		csvFormat = CSVFormatHelper.getDefaultCSVFormat();
		parser = CSVParser.parse(resource, charset, csvFormat);
		for (CSVRecord record : parser )
			list.add((Map<String, String>)record.toMap());
	}
	catch (IOException e) {
		log.error("Fail", e);
	}
	return list;
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:22,代码来源:HangManExerciseHintLoader.java

示例4: accept

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
@Override
public void accept(CSVRecord theRecord) {
    String code = theRecord.get("LOINC_NUM");
    if (isNotBlank(code)) {
        String longCommonName = theRecord.get("LONG_COMMON_NAME");
        String shortName = theRecord.get("SHORTNAME");
        String consumerName = theRecord.get("CONSUMER_NAME");
        String display = firstNonBlank(longCommonName, shortName, consumerName);

        ConceptEntity concept = new ConceptEntity(myCodeSystemVersion, code);
        concept.setDisplay(display);

        Validate.isTrue(!myCode2Concept.containsKey(code));
        myCode2Concept.put(code, concept);
    }
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:17,代码来源:TerminologyLoaderDao.java

示例5: parse

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
private ArrayList<Map<String,String>> parse()  {

		ArrayList<Map<String,String>> list;
		CSVParser parser;
		URL resource;
		CSVFormat csvFormat;
		Charset charset;
		list = new ArrayList<Map<String,String>> ();
		try {
			resource = ResourceHelper.getResource(isFromGameResourceInput(),fileName);
			charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
			csvFormat = CSVFormatHelper.getDefaultCSVFormat();
			parser = CSVParser.parse(resource, charset, csvFormat);
			for (CSVRecord record : parser )
				list.add(record.toMap());
		}
		catch (IOException e) {
			log.error("Fail", e);
		}
		return list;
		
	}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:23,代码来源:HangManExerciseDelimitedAreaLoader.java

示例6: createTags

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
private List <Tag>  createTags(CSVParser parser, Course course) {
	tagMap = new HashMap<>();
	ArrayList<Tag> tagList = new ArrayList<Tag>();
	for (CSVRecord csvRecord : parser) {
		String name = csvRecord.get(TagPoolColumn.TAG.ordinal()).toString();
		if (!tagMap.containsKey(name)){
			Tag tag = new Tag();
    	    tag.setName(name);
    	    tag.setCourse(course);
    
    	    tagMap.put(name, tag);
    	    
    	    tag.setNumber(tagMap.size());
    	    tagList.add(tag);
    	    
		}

	 }
	
	return tagList;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:22,代码来源:TagPoolCSVParser.java

示例7: parse

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
public List<Map<String,String>> parse() throws BuenOjoCSVParserException {
	List<Map<String,String>> list = new ArrayList<>();
	CSVParser parser = null;
	try {
		parser = CSVFormat.RFC4180.withHeader()
								.withDelimiter(',')
								.withAllowMissingColumnNames(true)
								.parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	} catch (IOException e) {
		throw new BuenOjoCSVParserException(e.getMessage());
	}
	
	for (CSVRecord record :parser) {
		Map<String,String> map = record.toMap();
		list.add(map);
	}
	
	return list;
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:21,代码来源:SatelliteImageMetadataParser.java

示例8: parse

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
public List<PhotoLocationSightPair> parse () throws IOException, BuenOjoCSVParserException {
	CSVParser parser =  CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	
	
	List<CSVRecord> records = parser.getRecords();
	if (records.size() == 0 ) {
		throw new BuenOjoCSVParserException("El archivos de miras no contiene registros");
	}
	ArrayList<PhotoLocationSightPair> sightPairs = new ArrayList<>(records.size());
	for (CSVRecord record : records) {
		
		PhotoLocationSightPair sight = new PhotoLocationSightPair();
		sight.setNumber(new Integer(record.get(PhotoLocationSightPairCSVColumn.id)));
		sight.setSatelliteX(new Integer(record.get(PhotoLocationSightPairCSVColumn.satCol)));
		sight.setSatelliteY(new Integer(record.get(PhotoLocationSightPairCSVColumn.satRow)));
		sight.setSatelliteTolerance(new Integer(record.get(PhotoLocationSightPairCSVColumn.satTolerancia)));
		sight.setTerrainX(new Integer(record.get(PhotoLocationSightPairCSVColumn.terCol)));
		sight.setTerrainY(new Integer(record.get(PhotoLocationSightPairCSVColumn.terRow)));
		sight.setTerrainTolerance(new Integer(record.get(PhotoLocationSightPairCSVColumn.terTolerancia)));
		
		sightPairs.add(sight);
		
	}
	return sightPairs;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:26,代码来源:PhotoLocationSightPairCSVParser.java

示例9: parse

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
public List<TagPair> parse() throws IOException {
	
	CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	
	
	ArrayList<TagPair> tagPairs = new ArrayList<>(AVG_ITEMS);
	for (CSVRecord record : parser ){
		
		TagPair pair = new TagPair();
		Integer tagSlotId = new Integer(record.get("id"));
		Integer tagNumber = new Integer(record.get("etiqueta"));
		
		pair.setTagSlotId(tagSlotId);
		Optional<Tag> optionalTag = tagList.stream().filter(isEqualToTagNumber(tagNumber)).findFirst();
		if (optionalTag.isPresent()){
			Tag tag = optionalTag.get(); 
			pair.setTag(tag);
			tagPairs.add(pair);			
		}else {
			log.debug("Attempt to get invalid tag with number: "+tagNumber);
		}
	}
	
	return tagPairs;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:26,代码来源:ImageCompletionSolutionCSVParser.java

示例10: parse

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
public List<TagCircle> parse() throws IOException, BuenOjoCSVParserException {

		ArrayList<TagCircle> list = new ArrayList<>(MAX_CIRCLES);

		CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(false).parse(new InputStreamReader(this.inputStream));
		
		for (CSVRecord record : parser ){
			TagCircle circle = new TagCircle();
			circle.setNumber(new Integer(record.get("id")));
			circle.setX(new Integer(record.get("col")));
			circle.setY(new Integer(record.get("row")));
			circle.setRadioPx(new Float(record.get("radioPx")));
			list.add(circle);

		}
		if (list.size()>MAX_CIRCLES){
			throw new BuenOjoCSVParserException("el archivo contiene mas de "+MAX_CIRCLES+ "áreas circulares");
		}
		return list;

	}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:22,代码来源:TagCircleCSVParser.java

示例11: parseLevels

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
public Integer[] parseLevels() throws BuenOjoCSVParserException, IOException{
	CSVRecord record = getRecords().get(0);
	String levels = record.get(PhotoLocationLandscapeLevelsCSVColumns.levels.ordinal());
	
	//Matcher m = Pattern.compile("(\\d*):(\\d*)").matcher(levels);
	String[] m = levels.split(":");
	if (m==null) {
		throw new BuenOjoCSVParserException("el formato del nivel es incorrecto: "+levels);
	}
	
	Integer[] n = new Integer[PhotoLocationLevelComponents.count.ordinal()];
	int lower = PhotoLocationLevelComponents.lowerLevel.ordinal();
	int higher = PhotoLocationLevelComponents.higherLevel.ordinal();
	n[lower] = new Integer(m[lower]);
	n[higher] = new Integer(m[higher]);

	return n;
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:20,代码来源:PhotoLocationLandscapeLevelsCSVParser.java

示例12: DataSet

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
/**
 * Creates a new dataset with column labels and data read from the given Reader, using a specified input format.
 *
 * @param reader       the Reader to read column labels and data from
 * @param input_format the format
 */
@SuppressWarnings("WeakerAccess")
public DataSet(final Reader reader, final CSVFormat input_format) {

    this();

    try (CSVParser parser = new CSVParser(reader, input_format.withHeader())) {

        labels.addAll(getColumnLabels(parser));

        for (final CSVRecord record : parser) {

            final List<String> items = csvRecordToList(record);
            final int size = items.size();

            // Don't add row if the line was empty.
            if (size > 1 || (size == 1 && items.get(0).length() > 0)) {
                records.add(items);
            }
        }

        reader.close();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:stacs-srg,项目名称:ciesvium,代码行数:32,代码来源:DataSet.java

示例13: read

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
/**
 * This method reads the file from @see {@link ReadFolder} and put into an array list the data we need.
 * We use here the API commons-csv.
 * Attention : tu run with the API you need to import him into the project @see README.
 * @param folderName.
 * @exception IOException | NumberFormatException : print error reading file.
 */
public void read(String folderName) {
	try {
		Reader in = new FileReader(folderName + "/" + file.getName());
		BufferedReader br = new BufferedReader(in);
		String firstLine = br.readLine();
		if (checkTheFile(firstLine)) {
			Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(br);	
			for (CSVRecord record : records) 
				if (record.get("Type").equals("WIFI") && !record.get("FirstSeen").contains("1970")) 
					inputWifi(record, firstLine);
			in.close();
			br.close();
		}
	}
	catch(IOException | NumberFormatException ex) { // If there is an error.
		System.out.println("Error reading file : " + ex);
		System.exit(0);
	}
}
 
开发者ID:orelshalom,项目名称:Assignment_1,代码行数:27,代码来源:ReadFile.java

示例14: iterator

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
@Override
public Iterator<Row> iterator() {
    return new Iterator<BulkUserImportReader.Row>() {
        Iterator<CSVRecord> i = csvParser.iterator();

        @Override
        public boolean hasNext() {
            return i.hasNext();
        }

        @Override
        public Row next() {
            CSVRecord record = i.next();
            return new Row(record);
        }

        @Override
        public void remove() {
            i.remove();
        }
    };
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:BulkUserImportReader.java

示例15: compareCSVFiles

import org.apache.commons.csv.CSVRecord; //导入依赖的package包/类
private void compareCSVFiles(String actualPath, String expectedPath) {
    try (CSVParser parserTranslatedFile = createCsvParser(actualPath, ",")) {
        try (CSVParser parserExpectedFile = createCsvParser(expectedPath, ",")) {
            Iterator<CSVRecord> translatedIterator = parserTranslatedFile.iterator();
            Iterator<CSVRecord> expectedIterator = parserExpectedFile.iterator();
            while (translatedIterator.hasNext() && expectedIterator.hasNext()) {
                CSVRecord translatedRecord = translatedIterator.next();
                CSVRecord expectedRecord = expectedIterator.next();
                compareCSVRecords(translatedRecord, expectedRecord);
            }
            if (translatedIterator.hasNext()) {
                fail("Actual file is longer (has more lines) than expected file");
            }
            if (expectedIterator.hasNext()) {
                fail("Expected file is longer (has more lines) than actual file");
            }
        }
    } catch (Exception e) {
        fail("Exception while iterating over files");
    }
}
 
开发者ID:kenshoo,项目名称:file-format-streaming-converter,代码行数:22,代码来源:XlsxToCsvConverterTest.java


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