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

com.github.skjolber.stcsv.DefaultStaticCsvMapper 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 */ public class DefaultStaticCsvMapper implements StaticCsvMapper { // https://stackoverflow.com/questions/28030465/performance-of-invoking-constructor-by-reflection private final Constructor> readerConstructor; private final Constructor> readerArrayConstructor; public DefaultStaticCsvMapper(Class> cls) throws Exception { this.readerConstructor = cls.getConstructor(Reader.class); this.readerArrayConstructor = cls.getConstructor(Reader.class, char[].class, int.class, int.class); } public AbstractCsvReader newInstance(Reader reader) { try { return readerConstructor.newInstance(reader); } catch (Exception e) { throw new RuntimeException(e); // should never happen } } public AbstractCsvReader newInstance(Reader reader, char[] current, int offset, int length) { try { return readerArrayConstructor.newInstance(reader, current, offset, length); } catch (Exception e) { throw new RuntimeException(e); // should never happen } } /* public AbstractCsvClassFactory newInstance(Reader reader, boolean skipHeader) throws IOException { if(skipHeader) { do { int read = reader.read(); if(read == -1) { return new NullCsvClassFactory(); } if(read == (int)'\n') { break; } } while(true); } try { return constructor.newInstance(reader); } catch (Exception e) { throw new RuntimeException(); // should never happen } } */ }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy