本文整理汇总了Java中org.supercsv.io.CsvBeanReader类的典型用法代码示例。如果您正苦于以下问题:Java CsvBeanReader类的具体用法?Java CsvBeanReader怎么用?Java CsvBeanReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CsvBeanReader类属于org.supercsv.io包,在下文中一共展示了CsvBeanReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
public List<Airline> deserialize(InputStream in) throws IOException {
InputStreamReader inputStreamReader = new InputStreamReader(in);
ICsvBeanReader csvBeanReader = new CsvBeanReader(inputStreamReader, CsvPreference.STANDARD_PREFERENCE);
final String[] header = {null, "name", "alias", "iataCode", "icaoCode", "callsign", "country", null};
Airline airline = null;
List<Airline> airlines = new ArrayList<>();
try {
while ((airline = csvBeanReader.read(Airline.class, header, getCellProcessors())) != null) {
System.out.println("deserialized " + airline);
airlines.add(airline);
}
} finally {
if (csvBeanReader != null) {
csvBeanReader.close();
}
}
return airlines;
}
示例2: deserialize
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
public List<Airport> deserialize(InputStream in) throws IOException {
InputStreamReader inputStreamReader = new InputStreamReader(in);
ICsvBeanReader csvBeanReader = new CsvBeanReader(inputStreamReader, CsvPreference.STANDARD_PREFERENCE);
final String[] header = {null, "name", "city", "country", "iataCode", "icaoCode", "latitude", "longitude", null, null, null, null, null, null};
Airport airport = null;
List<Airport> airports = new ArrayList<>();
try {
while ((airport = csvBeanReader.read(Airport.class, header, getCellProcessors())) != null) {
System.out.println("deserialized " + airport);
airports.add(airport);
}
} finally {
if (csvBeanReader != null) {
csvBeanReader.close();
}
}
return airports;
}
示例3: deserialize
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
public List<FlightConnection> deserialize(InputStream in) throws IOException {
InputStreamReader inputStreamReader = new InputStreamReader(in);
ICsvBeanReader csvBeanReader = new CsvBeanReader(inputStreamReader, CsvPreference.STANDARD_PREFERENCE);
final String[] header = {"airlineIataCode", null, "sourceAirportIataCode", null, "destinationAirportIataCode", null, "codeshare", "stops", null};
FlightConnection flightConnection = null;
List<FlightConnection> flightConnections = new ArrayList<>();
try {
while ((flightConnection = csvBeanReader.read(FlightConnection.class, header, getCellProcessors())) != null) {
System.out.println("deserialized " + flightConnection);
flightConnections.add(flightConnection);
}
} finally {
if (csvBeanReader != null) {
csvBeanReader.close();
}
}
return flightConnections;
}
示例4: readGpsFixesFromFile
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
private List<GpsRecordAnnotation> readGpsFixesFromFile(FileReader fileReader, String csvFileName) {
List<GpsRecordAnnotation> results = new LinkedList<GpsRecordAnnotation>();
CsvBeanReader beanReader = new CsvBeanReader(fileReader, CsvPreference.STANDARD_PREFERENCE);
try {
String[] headers = beanReader.getHeader(true);
if (hasIncorrectHeaders(headers)) {
closeReaders(fileReader, beanReader);
throw getUnableToReadFileExceptionCauseOfHeaders(csvFileName);
}
getGpsFixesFromReader(results, beanReader, headers);
closeReaders(fileReader, beanReader);
} catch (IOException | NullPointerException e) {
throw getUnableToReadFileExceptionCauseUnknown(csvFileName, e);
}
return results;
}
示例5: read
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
@Override
public List<T> read(InputStream is)
throws Exception {
List<T> elements = new ArrayList<T>();
try {
ICsvBeanReader reader = new CsvBeanReader(new InputStreamReader(is), CsvPreference.EXCEL_PREFERENCE);
String[] headers = mapHeaderNames(reader.getHeader(true));
T element;
while ((element = reader.read(type, headers, cellProcessors)) != null) {
elements.add(element);
}
} catch (Exception e) {
throw e;
}
return elements;
}
示例6: 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());
}
示例7: 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());
}
示例8: testReturnsTypedBean
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
@Test
public void testReturnsTypedBean() throws Exception {
int methodCounter = 0;
Method[] methods = CsvBeanReader.class.getMethods();
for( Method method : methods ) {
if( method.getName().equals("read") ) {
try {
Type genericReturnType = method.getGenericReturnType();
Assert.assertNotNull(genericReturnType);
Assert.assertEquals("T", genericReturnType.getTypeName());
methodCounter++;
}
catch(Exception e) {
Assert.fail(e.getMessage());
}
}
}
Assert.assertTrue(methodCounter > 0);
}
示例9: 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);
}
示例10: setup
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
@Override
public void setup(OperatorContext context)
{
delimitedParserSchema = new DelimitedSchema(schema);
preference = new CsvPreference.Builder(delimitedParserSchema.getQuoteChar(),
delimitedParserSchema.getDelimiterChar(), delimitedParserSchema.getLineDelimiter()).build();
nameMapping = delimitedParserSchema.getFieldNames().toArray(
new String[delimitedParserSchema.getFieldNames().size()]);
header = StringUtils.join(nameMapping, (char)delimitedParserSchema.getDelimiterChar() + "");
processors = getProcessor(delimitedParserSchema.getFields());
csvStringReader = new ReusableStringReader();
csvMapReader = new CsvMapReader(csvStringReader, preference);
csvBeanReader = new CsvBeanReader(csvStringReader, preference);
}
示例11: initalizeBeanReader
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
private void initalizeBeanReader(String file) {
beanReader = new CsvBeanReader(new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(file))),CsvPreference.STANDARD_PREFERENCE);
try {
@SuppressWarnings("unused")
final String[] header = beanReader.getHeader(true);
} catch (IOException e1) {
e1.printStackTrace();
}
}
示例12: initalizeBeanReader
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
private void initalizeBeanReader(String file) {
beanReader = new CsvBeanReader(new BufferedReader(
new InputStreamReader(getClass().getClassLoader()
.getResourceAsStream(file))),
CsvPreference.STANDARD_PREFERENCE);
try {
@SuppressWarnings("unused")
final String[] header = beanReader.getHeader(true);
} catch (IOException e1) {
errorLog.add(e1.toString());
}
}
示例13: open
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
/**
*
* @param conf
* @param context
* @param collector
*/
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
this.collector = collector;
CellProcessor[] p = {new Optional(), new Optional(),
new Optional(new Token(" ", null, new ParseDate("yyyy-MM-dd HH:mm:ss.SSS", true))),
new Optional(new ParseDouble()), new Optional(new ParseDouble()), new Optional()};
this.processors = p;
File[] files = (new File("src/test/resources")).listFiles();
ComparableFileByModified[] pairs = new ComparableFileByModified[files.length];
for (int i = 0; i < files.length; i++) {
pairs[i] = new ComparableFileByModified(files[i]);
}
Arrays.sort(pairs);
this.beanReader = new CsvBeanReader[files.length];
for (int i = 0; i < pairs.length; i++) {
try {
this.beanReader[i] = new CsvBeanReader(new FileReader(pairs[i].f), CsvPreference.STANDARD_PREFERENCE);
} catch (FileNotFoundException ex) {
Logger.getLogger(EsperBoltStressTest.class.getName()).log(Level.SEVERE, null, ex);
this.beanReader[i] = null;
}
}
this.beanReaderCount = 0;
startMilis = System.currentTimeMillis();
}
示例14: importStream
import org.supercsv.io.CsvBeanReader; //导入依赖的package包/类
@Override
public void importStream(InputStream inputStream, OnItemHandler handler, String charSetName) throws Exception {
Reader reader = new InputStreamReader(inputStream, charSetName);
ICsvBeanReader csvBeanReader = new CsvBeanReader(reader, this.preference);
Object obj;
while ((obj = csvBeanReader.<T>read(getDataClass(), this.fieldNames, this.processors)) != null) {
handler.onItem(obj);
}
}
示例15: 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);
}