Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
 	Milyn - Copyright (C) 2006
 
 	This library is free software; you can redistribute it and/or
 	modify it under the terms of the GNU Lesser General Public
 	License (version 2.1) as published by the Free Software
 	Foundation.
 
 	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU Lesser General Public License for more details:
	http://www.gnu.org/licenses/lgpl.txt
*/
package org.milyn.csv.prog;
CSV java.util.List Binder class.

Simple CSV to Object java.util.List binding class.

Exmaple usage:

 public class PeopleBinder {
     // Create and cache the binder instance..
     private CSVListBinder binder = new CSVListBinder("firstname,lastname,gender,age,country", Person.class);

     public List<Person> bind(Reader csvStream) {
         return binder.bind(csvStream);
     }
 }
 

Author(s):
tom.fennelly@jboss.com
public class CSVListBinder {
    private String beanId = UUID.randomUUID().toString();
    private Smooks smooks;
    public CSVListBinder(String fieldsClass recordType) {
        AssertArgument.isNotNullAndNotEmpty(fields"fields");
        AssertArgument.isNotNull(recordType"recordType");
         = new Smooks();
        .setReaderConfig(new CSVReaderConfigurator(fields)
                .setBinding(new CSVBinding(recordType.)));
    }
    public List bind(Reader csvStream) {
        AssertArgument.isNotNull(csvStream"csvStream");
        JavaResult javaResult = new JavaResult();
        .filterSource(new StreamSource(csvStream), javaResult);
        return (ListjavaResult.getBean();
    }
    public List bind(InputStream csvStream) {
        return bind(new InputStreamReader(csvStream));
    }
New to GrepCode? Check out our FAQ X