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
 	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	See the GNU Lesser General Public License for more details:
package org.milyn.csv.prog;
CSV java.util.Map Binder class.

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

Exmaple usage:

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

     public Map<String, Person> bind(Reader csvStream) {
         return binder.bind(csvStream);

public class CSVMapBinder {
    private String beanId = UUID.randomUUID().toString();
    private Smooks smooks;
    public CSVMapBinder(String fieldsClass recordTypeString keyField) {
         = new Smooks();
        .setReaderConfig(new CSVReaderConfigurator(fields)
                .setBinding(new CSVBinding(recordType.).setKeyField(keyField)));
    public Map bind(Reader csvStream) {
        JavaResult javaResult = new JavaResult();
        .filterSource(new StreamSource(csvStream), javaResult);
        return (MapjavaResult.getBean();
    public Map bind(InputStream csvStream) {
        return bind(new InputStreamReader(csvStream));
New to GrepCode? Check out our FAQ X