本文整理汇总了Java中au.com.bytecode.opencsv.bean.CsvToBean.parse方法的典型用法代码示例。如果您正苦于以下问题:Java CsvToBean.parse方法的具体用法?Java CsvToBean.parse怎么用?Java CsvToBean.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类au.com.bytecode.opencsv.bean.CsvToBean
的用法示例。
在下文中一共展示了CsvToBean.parse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParse
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
public void testParse() {
String s = "n,o,foo\n" +
"kyle,123456,emp123\n" +
"jimmy,abcnum,cust09878";
HeaderColumnNameTranslateMappingStrategy strat = new HeaderColumnNameTranslateMappingStrategy();
strat.setType(TestBean.class);
Map map = new HashMap();
map.put("n", "name");
map.put("o", "orderNumber");
map.put("foo", "id");
strat.setColumnMapping(map);
CsvToBean csv = new CsvToBean();
List list = csv.parse(strat, new StringReader(s));
assertNotNull(list);
assertTrue(list.size() == 2);
TestBean bean = (TestBean)list.get(0);
assertEquals("kyle", bean.getName());
assertEquals("123456", bean.getOrderNumber());
assertEquals("emp123", bean.getId());
}
示例2: testParse
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
public void testParse() {
String s = "" +
"kyle,123456,emp123\n" +
"jimmy,abcnum,cust09878";
ColumnPositionMappingStrategy strat = new ColumnPositionMappingStrategy();
strat.setType(TestBean.class);
String[] columns = new String[] {"name", "orderNumber", "id"};
strat.setColumnMapping(columns);
CsvToBean csv = new CsvToBean();
List list = csv.parse(strat, new StringReader(s));
assertNotNull(list);
assertTrue(list.size() == 2);
TestBean bean = (TestBean)list.get(0);
assertEquals("kyle", bean.getName());
assertEquals("123456", bean.getOrderNumber());
assertEquals("emp123", bean.getId());
}
示例3: testOpenCsvMapper
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
@Benchmark
public void testOpenCsvMapper(final Blackhole blackhole) throws Exception {
CsvToBean csvToBean = new CsvToBean();
Reader reader = getReader();
try {
List<?> list = null;
CSVReader csvreader = new CSVReader(reader);
list = csvToBean.parse(strategy, csvreader);
blackhole.consume(list);
}finally {
reader.close();
}
}
示例4: initializeMapping
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
public static void initializeMapping(){
cobasMappings = new ArrayList<CobasMiraMappingLabitem>();
String csvFilename =
CoreHub.localCfg.get(Preferences.MAPPINGSCSVFILE,
Preferences.getDefaultMappingCSVLocation());
try {
CsvToBean csvBean = new CsvToBean();
List csvList = csvBean.parse(getMappingStrategy(), new FileReader(csvFilename));
for (Object object : csvList) {
CobasMiraMappingLabitem cmlItem = (CobasMiraMappingLabitem) object;
cobasMappings.add(cmlItem);
}
} catch (FileNotFoundException e) {
Status status =
new Status(IStatus.WARNING, Activator.PLUGIN_ID, "CSV Mapping File nicht gefunden",
e);
StatusManager.getManager().handle(status, StatusManager.SHOW);
}
cobasMappings.remove(0);
}
示例5: testParse
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
public void testParse() {
String s = "name,orderNumber,num\n" +
"kyle,abc123456,123\n" +
"jimmy,def098765,456";
HeaderColumnNameMappingStrategy strat = new HeaderColumnNameMappingStrategy();
strat.setType(TestBean.class);
CsvToBean csv = new CsvToBean();
List list = csv.parse(strat, new StringReader(s));
assertNotNull(list);
assertTrue(list.size() == 2);
TestBean bean = (TestBean)list.get(0);
assertEquals("kyle", bean.getName());
assertEquals("abc123456", bean.getOrderNumber());
assertEquals(123, bean.getNum());
}
示例6: parseCsv
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
public List<T> parseCsv() throws IOException {
ClassPathResource classPathResource = new ClassPathResource(getClassPathFilePath(), this.getClass().getClassLoader());
InputStreamReader ioReader = new InputStreamReader(classPathResource.getInputStream(), "UTF-8");
CSVReader reader = new CSVReader(ioReader, ';');
ColumnPositionMappingStrategy<T> strat = new ColumnPositionMappingStrategy<>();
strat.setType(getDestinationClass());
strat.setColumnMapping(getColumnMapping());
CsvToBean<T> csv = getParser();
return csv.parse(strat, reader);
}
示例7: testOpenCsvMapper
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
@Benchmark
public void testOpenCsvMapper(final Blackhole blackhole) throws Exception {
CsvToBean<SmallBenchmarkObject> csvToBean = new CsvToBean<SmallBenchmarkObject>();
List<SmallBenchmarkObject> list = null;
CSVReader csvreader = new CSVReader(reader);
list = csvToBean.parse(strategy, csvreader);
blackhole.consume(list);
}
示例8: parseCreationFile
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
public static List<Record> parseCreationFile(String path, char delimiter) throws IOException {
ColumnPositionMappingStrategy<Record> strategy = new ColumnPositionMappingStrategy<Record>();
strategy.setType(Record.class);
String[] columns = new String[] {"category", "name", "template", "url"};
strategy.setColumnMapping(columns);
CSVReader reader = new CSVReader(new FileReader(path), delimiter, '\"', 1);
CsvToBean<Record> csv = new CsvToBean<Record>();
return csv.parse(strategy, reader);
}
示例9: testMappingStrategyRead
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
/**
* This approach seems to fail with embedded newlines; that might be a weakness of
* the mapping strategy support classes.
*
* @param originalCommentText
* @throws FileNotFoundException
*/
protected void testMappingStrategyRead(String originalCommentText)
throws FileNotFoundException {
ColumnPositionMappingStrategy mappingStrategy = new ColumnPositionMappingStrategy();
mappingStrategy.setType(MyBean.class);
String[] columns = new String[]{"name", "value", "amount1", "currency", "comments"}; // the fields to bind to in your JavaBean
mappingStrategy.setColumnMapping(columns);
CsvToBean csv = new CsvToBean();
CSVReader reader = new CSVReader(new FileReader(filePath), Constants.DEFAULT_SEPARATOR, Constants.DEFAULT_QUOTE_CHARACTER, Constants.DEFAULT_ESCAPE_CHARACTER, 0, false, false);
List<MyBean> list = csv.parse(mappingStrategy, reader);
if (list.size() != 3) {
System.out.println("Error - list size is wrong.");
}
MyBean myBean = list.get(2);
if (!myBean.getName().equals("field1")) {
System.out.println("MappingStrategy Assert Error: Name is wrong.");
}
if (!myBean.getValue().equals("3.0")) {
System.out.println("MappingStrategy Assert Error: Value is wrong.");
}
if (!myBean.getAmount1().equals("3,147.25")) {
System.out.println("MappingStrategy Assert Error: Amount1 is wrong.");
}
if (!myBean.getCurrency().equals("$3,147.26")) {
System.out.println("MappingStrategy Assert Error: Currency is wrong.");
}
printfield("MyBeanComments: ", myBean.getComments());
printfield("OriginalCommentText: ", originalCommentText);
if (!myBean.getComments().equals(originalCommentText)) {
System.out.println("MappingStrategy Assert Error: Comment is wrong.");
}
}
示例10: readBeans
import au.com.bytecode.opencsv.bean.CsvToBean; //导入方法依赖的package包/类
List<Object> readBeans() throws IOException {
final CGLibMappingStrategy strategy = new CGLibMappingStrategy();
final CsvToBean<Object> csvToBean = new CsvToBean<>();
try (final CSVReader reader = new CSVReader(Files.newBufferedReader(metadataFile, charset),
separator, quote, escape, skipLines, strictQuotes, ignoreLeadingWhiteSpace)) {
return csvToBean.parse(strategy, reader);
}
}