<?xml version="1.0" encoding="UTF-8"?>
<beanio xmlns="http://www.beanio.org/2012/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="fileTabellaSconti" format="csv">
<parser>
<property name="delimiter" value=";" />
<property name="unquotedQuotesAllowed" value="true" />
<property name="whitespaceAllowed" value="true" />
</parser>
<record name="tabellaSconti" class="map" occurs="1">
<segment name="sconto" class="map" >
<field name="categoria" />
<field name="nome" />
<field name="tipologia" />
<field name="profilo" />
</segment>
<field name="valore_sconto" type="java.lang.Integer" />
<field name="codice_sts" />
<field name="sconto_equivalente" type="java.lang.Integer" />
</record>
</stream>
</beanio>
public static void writer()
{
// create a StreamFactory
StreamFactory factory = StreamFactory.newInstance();
// load the mapping file
factory.load(new File("map_sconto.xml"));
BeanWriter out = factory.createWriter("fileTabellaSconti", new File("employee.csv"));
int c = 0;
while (c < 5)
{
c++;
Map<String, Object> record = new HashMap<String, Object>();
Map<String, Object> sconto = new HashMap<String, Object>();
sconto.put("categoria", "cat_"+c);
sconto.put("nome", "nome_"+c);
sconto.put("tipologia", "tipologia_"+c);
sconto.put("profilo", "profilo_"+c);
record.put( "sconto" , sconto );
record.put( "valore_sconto" , c );
record.put( "codice_sts" , "sts_"+c );
record.put( "sconto_equivalente" , c);
System.out.println(record);
out.write(record);
}
out.flush();
out.close();
}