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


Java CsvBeanReader.read方法代码示例

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


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

示例1: testConvertsToBasicObjects

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
@Test
public void testConvertsToBasicObjects() throws Exception {
	String csv = "Connor|John|16|1999-07-12|6" + decimalFormatSymbols.getDecimalSeparator() + "65\r\n";
	String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
	CellProcessor[] processors = { new NotNull(), new NotNull(), new ParseInt(), new ParseDate("yyyy-MM-dd"),
		new ParseBigDecimal(decimalFormatSymbols) };
	
	CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
	CsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), customPreference);
	FeatureBean character = beanReader.read(FeatureBean.class, mapping, processors);
	
	Assert.assertNotNull(character);
	Assert.assertEquals("John", character.getFirstName());
	Assert.assertEquals("Connor", character.getLastName());
	Assert.assertEquals(16, character.getAge());
	Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("1999-07-12"), character.getBirthDate());
	Assert.assertEquals(new BigDecimal(6.65, new MathContext(3)), character.getSavings());
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:19,代码来源:ReadingFeaturesTest.java

示例2: testConverterSupport

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
@Test
public void testConverterSupport() throws Exception {
	String csv = "Connor|John|16|1999-07-12|6" + decimalFormatSymbols.getDecimalSeparator() + "65\r\n";
	String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
	CellProcessor[] processors = { new NotNull(), new NotNull(), new ParseInt(), new ParseDate("yyyy-MM-dd"),
		new ParseBigDecimal(decimalFormatSymbols) };
	
	CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
	CsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), customPreference);
	FeatureBean character = beanReader.read(FeatureBean.class, mapping, processors);
	
	Assert.assertNotNull(character);
	Assert.assertEquals("John", character.getFirstName());
	Assert.assertEquals("Connor", character.getLastName());
	Assert.assertEquals(16, character.getAge());
	Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("1999-07-12"), character.getBirthDate());
	Assert.assertEquals(new BigDecimal(6.65, new MathContext(3)), character.getSavings());
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:19,代码来源:ReadingFeaturesTest.java

示例3: getDataSet

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
@Override
public DataSet<LocatedRow> getDataSet(SpliceOperation op, DataSetProcessor dsp, ExecRow execRow) throws StandardException {
    operationContext = dsp.createOperationContext(op);

    //Create an arraylist to store the key / value pairs
    ArrayList<LocatedRow> items = new ArrayList<LocatedRow>();

    try {

        int numRcds = this.records == null ? 0 : this.records.size();

        if (numRcds > 0) {

            LOG.info("Records to process:" + numRcds);
            //Loop through each record convert to a SensorObject
            //and then set the values
            for (String csvString : records) {
                CsvBeanReader beanReader = new CsvBeanReader(new StringReader(csvString), CsvPreference.STANDARD_PREFERENCE);
                RFIDMessage msg = beanReader.read(RFIDMessage.class, header, processors);
                items.add(new LocatedRow(msg.getRow()));
            }
        }
    } catch (Exception e) {
        LOG.error("Exception processing RFIDMessageVTI", e);
    } finally {
        operationContext.popScope();
    }
    return new ControlDataSet<>(items);
}
 
开发者ID:splicemachine,项目名称:splice-community-sample-code,代码行数:30,代码来源:RFIDMessageVTI.java

示例4: getGpsFixesFromReader

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
private void getGpsFixesFromReader(List<GpsRecordAnnotation> results, CsvBeanReader beanReader, String[] headers)
        throws IOException {
    GpsRecordAnnotation gpsFix = null;
    do {
        gpsFix = beanReader.read(GpsRecordAnnotation.class, headers, getProcessors());
        if (gpsFix != null) {
            results.add(gpsFix);
        }

    } while (gpsFix != null);
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:GpsRecordAnnotationCsvLoader.java

示例5: readRecordsFromFile

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
private List<GpsRecordDto> readRecordsFromFile(CsvBeanReader beanReader, String[] headers, CellProcessor[] processors)
        throws IOException {
    List<GpsRecordDto> results = new LinkedList<GpsRecordDto>();
    GpsRecordDto gpsRecording = null;
    do {
        gpsRecording = beanReader.read(GpsRecordDto.class, headers, processors);
        if (gpsRecording != null) {
            results.add(gpsRecording);
        }
    } while (gpsRecording != null);
    return results;
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:13,代码来源:GpsRecordDtoCsvLoader.java

示例6: testColumnNameBasedMapping

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
@Test
public void testColumnNameBasedMapping() throws IOException {
	String csv = "Connor,John\r\n";
	String[] mapping = { "lastName", "firstName" };
	
	CsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), STANDARD_PREFERENCE);
	FeatureBean character = beanReader.read(FeatureBean.class, mapping);
	
	Assert.assertNotNull(character);
	Assert.assertEquals("John", character.getFirstName());
	Assert.assertEquals("Connor", character.getLastName());
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:13,代码来源:ReadingFeaturesTest.java

示例7: testConvertsToPrimitives

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
@Test
public void testConvertsToPrimitives() throws IOException {
	String csv = "Connor,John,16\r\n";
	String[] mapping = { "lastName", "firstName", "age" };
	CellProcessor[] processors = { new NotNull(), new NotNull(), new ParseInt() };
	
	CsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), STANDARD_PREFERENCE);
	FeatureBean character = beanReader.read(FeatureBean.class, mapping, processors);
	
	Assert.assertNotNull(character);
	Assert.assertEquals("John", character.getFirstName());
	Assert.assertEquals("Connor", character.getLastName());
	Assert.assertEquals(16, character.getAge());
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:15,代码来源:ReadingFeaturesTest.java

示例8: testDateSupport

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
@Test
public void testDateSupport() throws Exception {
	String csv = "1999-07-12";
	String[] mapping = { "birthDate" };
	CellProcessor[] processors = { new ParseDate("yyyy-MM-dd") };
	
	CsvBeanReader beanReader = new CsvBeanReader(new StringReader(csv), STANDARD_PREFERENCE);
	FeatureBean character = beanReader.read(FeatureBean.class, mapping, processors);
	
	Assert.assertNotNull(character);
	Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("1999-07-12"), character.getBirthDate());
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:13,代码来源:ReadingFeaturesTest.java

示例9: getNextKiekerTraceEntry

import org.supercsv.io.CsvBeanReader; //导入方法依赖的package包/类
private KiekerTraceEntry getNextKiekerTraceEntry(final CsvBeanReader reader) throws IOException {
	return reader.read(KiekerTraceEntry.class, KiekerTraceEntry.getFieldDescription(), KiekerTraceEntry.getCellProcessors());
}
 
开发者ID:DaGeRe,项目名称:KoPeMe,代码行数:4,代码来源:KiekerTrace.java


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