InputStream is = new ByteArrayInputStream(theContent.getBytes()); BufferedReader br = new BufferedReader(new InputStreamReader(is)); CSVReader<String[]> csvReader = new CSVReaderBuilder<String[]>(br).strategy(new CSVStrategy('\t', '\b', '#', true, true)).entryParser(new EntryParser()).build(); while ((nextLine = csvReader.readNext()) != null) { // Do Parsing work and Store to SQLite Database }
strategy = new CSVStrategy(',', '"', CSVStrategy.COMMENTS_DISABLED, CSVStrategy.ESCAPE_DISABLED, false, false, false, true); String sep = params.get(SEPARATOR); if (sep!=null) { if (sep.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid separator:'"+sep+"'"); strategy.setDelimiter(sep.charAt(0)); strategy.setEncapsulator((char)-2); // TODO: add CSVStrategy.ENCAPSULATOR_DISABLED strategy.setEscape(escape.charAt(0)); } else { if (encapsulator != null) { strategy.setEncapsulator(encapsulator.charAt(0)); strategy.setEscape(ch); if (ch == '\\') { strategy.setUnicodeEscapeInterpretation(true);
public class MyCSVReader<T> { private Class<T> clazz; public MyCSVReader(Class<T> clazz) { this.clazz = clazz; } public List<T> readData(File file) { ValueProcessorProvider provider = new ValueProcessorProvider(); CSVEntryParser<T> parser = new AnnotationEntryParser<T>(clazz, provider); CSVStrategy strategy = new CSVStrategy(',', '"', '#', true, true); CSVReaderBuilder builder = new CSVReaderBuilder<T>(file); CSVReader<T> reader = builder.entryParser(parser ).strategy(strategy).build(); return reader.readAll(); } }
: CharUtils.toChar(loader.getEncapsulator()); log.info(String.format("delimiter %d encapsulator %d", (int)delimiter, (int)encapsulator)); CSVStrategy strategy = new CSVStrategy(delimiter, encapsulator, CSVStrategy.COMMENTS_DISABLED, CSVStrategy.ESCAPE_DISABLED, true, true, false, true); parser = new CSVParser(reader, strategy);
char fesc = escStr==null || encStr.length()==0 ? CSVStrategy.ESCAPE_DISABLED : escStr.charAt(0); CSVStrategy fstrat = new CSVStrategy(fsep,fenc,CSVStrategy.COMMENTS_DISABLED,fesc, false, false, false, false); adders[i] = new CSVLoader.FieldSplitter(fstrat, adders[i]);