|
Project Information
Featured
Downloads
Links
|
BeanFiles is a java library for importing and exporting javabeans to/from various file formats. Right now, it only supports importing from csv using opencsv and xls using POI. Check out the examples. Beanfiles aims to facilitate type conversion and multiple input/output formats while reusing some of the underlying translation components. The library currently supports importing only, but has some useful features. It supports the following:
A nice use-case is creating beans with the beanfiles library, then using Hibernate to store objects to a relational model. There's a Google group for discussing this project: http://groups.google.com/group/beanfiles Example UsageConsider the following csv file: property1,property2,property3,property4,property5 line1_prop1,line1_prop2,line1_prop3,1,FALSE line2_prop1,line2_prop2,line2_prop3,2,TRUE In order to map this data to the following Java Bean: public class SimpleBean {
private String property1;
private String property2;
private String property3;
private int property4;
private boolean property5;
public SimpleBean() {}
public String getProperty1() {
return property1;
}
public void setProperty1(String property1) {
this.property1 = property1;
}
...
}
Here's the Beanfiles code: InputStream input = getInputStream("files/csv/simple_properties.csv");
ReaderIterator<SimpleBean> iterator = new CSVReaderIterator<SimpleBean>(SimpleBean.class, input);
input.close();
SimpleBean bean1 = iterator.next();
SimpleBean bean2 = iterator.next();
|