本文整理汇总了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());
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}