All Downloads are FREE. Search and download functionalities are using the official Maven repository.

opencsv.utils.CsvMapperUtil Maven / Gradle / Ivy

package opencsv.utils;

import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class CsvMapperUtil {

    private static final Map columnMap = new HashMap();

    private CsvMapperUtil() {

    }

    public static  List fromCsv(Class type, Reader reader) {

        return new CsvMapper(type).withMapping(getColumnMap(type)).fromCsv(reader);
    }

    private static synchronized  CsvColumnMapping getColumnMap(Class type) {
        final String key = type.getName();

        if (!columnMap.containsKey(key)) {
            columnMap.put(key, new CsvColumnMapping(type));
        }

        return columnMap.get(key);
    }

    public static  void toCsv(Class type, List list, Writer writer) throws Exception {
        new CsvMapper(type).withMapping(getColumnMap(type)).toCsv(writer, list);
    }

    public static void Dispose() {
        columnMap.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy