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

com.github.skjolber.stcsv.DefaultStaticCsvMapper2 Maven / Gradle / Ivy

There is a newer version: 1.0.25
Show newest version
package com.github.skjolber.stcsv;

import java.io.Reader;
import java.lang.reflect.Constructor;

/**
 * 
 * Static CSV parser generator - for specific parser implementation
 * 

* Thread-safe. * @param csv line output value * @param intermediate processor */ public class DefaultStaticCsvMapper2 implements StaticCsvMapper2{ // https://stackoverflow.com/questions/28030465/performance-of-invoking-constructor-by-reflection private final Constructor> readerConstructor; private final Constructor> readerArrayConstructor; public DefaultStaticCsvMapper2(Class> cls, Class delegate) throws Exception { this.readerConstructor = cls.getConstructor(Reader.class, delegate); this.readerArrayConstructor = cls.getConstructor(Reader.class, char[].class, int.class, int.class, delegate); } public AbstractCsvReader newInstance(Reader reader, D delegate) { try { return readerConstructor.newInstance(reader, delegate); } catch (Exception e) { throw new RuntimeException(e); // should never happen } } public AbstractCsvReader newInstance(Reader reader, char[] current, int offset, int length, D delegate) { try { return readerArrayConstructor.newInstance(reader, current, offset, length, delegate); } catch (Exception e) { throw new RuntimeException(e); // should never happen } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy