Example usage for org.apache.commons.csv.writer CSVField CSVField

List of usage examples for org.apache.commons.csv.writer CSVField CSVField

Introduction

In this page you can find the example usage for org.apache.commons.csv.writer CSVField CSVField.

Prototype

public CSVField(String name) 

Source Link

Usage

From source file:org.apache.camel.dataformat.csv.CsvDataFormat.java

private synchronized void updateFieldsInConfig(Set<?> set, Exchange exchange) {
    for (Object value : set) {
        if (value != null) {
            String text = exchange.getContext().getTypeConverter().convertTo(String.class, value);
            // do not add field twice
            if (config.getField(text) == null) {
                CSVField field = new CSVField(text);
                config.addField(field);/*w ww .  j  a  va  2s.  c o m*/
            }
        }
    }
}

From source file:org.apache.camel.dataformat.csv.CsvRouteTest.java

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() {
            // START SNIPPET: marshalRoute
            from("direct:start").marshal().csv().to("mock:result");
            // END SNIPPET: marshalRoute

            from("direct:startMulti").marshal().csv().to("mock:resultMulti");

            CsvDataFormat customCsv = new CsvDataFormat();
            CSVConfig custom = new CSVConfig();
            custom.setDelimiter(';');
            custom.addField(new CSVField("foo"));
            custom.addField(new CSVField("baz"));
            custom.addField(new CSVField("bar"));
            customCsv.setConfig(custom);
            customCsv.setAutogenColumns(false);

            from("direct:startMultiCustom").marshal(customCsv).to("mock:resultMultiCustom");

            // START SNIPPET: unmarshalRoute
            from("file:src/test/resources/?fileName=daltons.csv&noop=true").unmarshal().csv()
                    .to("mock:daltons");
            // END SNIPPET: unmarshalRoute
        }// ww w.  j  a v  a  2 s .c  o  m
    };
}