@Override public void start() throws IOException { // First line contains the column names. First column expected to be the // row key if (hasHeaderLine) { names = parser.getLine(); } }
@Override public void start() throws IOException { // First line contains the column names. First column expected to be the // row key if (hasHeaderLine) { parser.getLine(); } }
CSVParser parser = new CSVParser(new FileReader(file)); String[] line; while ((line = parser.getLine()) != null) { // process }
private List<String> fromListText(String property) { List<String> result = new ArrayList<String>(); if (property.length()>0) { //an empty string as assumed to be an empty list, rather than a list with 1 empty string in it! StringReader reader = new StringReader(property); CSVParser csvReader = new CSVParser(reader); try { for (String v : csvReader.getLine()) { result.add(v); } } catch (IOException e) { logger.error("Exception occurred parsing CSV properties:"+property,e); } } return result; }
private List<String> fromListText(String property) { List<String> result = new ArrayList<String>(); if (property.length()>0) { //an empty string as assumed to be an empty list, rather than a list with 1 empty string in it! StringReader reader = new StringReader(property); CSVParser csvReader = new CSVParser(reader); try { for (String v : csvReader.getLine()) { result.add(v); } } catch (IOException e) { logger.error("Exception occurred parsing CSV properties:"+property,e); } } return result; }
@Override public List<Pair<String, String>> next() throws IOException { // Iterate rows String[] row = parser.getLine(); if (null == row) return null; List<Pair<String, String>> columns = new ArrayList<Pair<String, String>>(); // Build row mutation for all columns for (int i = 0; i < row.length; i++) { if (i >= names.length) { // Ignore past size of names break; } columns.add(Pair.create(names[i], row[i])); } return columns; } }
@Override public List<Pair<String, String>> next() throws IOException { // Iterate rows String[] row = parser.getLine(); if (null == row) return null; List<Pair<String, String>> columns = new ArrayList<Pair<String, String>>(); // Build row mutation for all columns columns.add(Pair.create("key", row[0])); if (row.length == 3) columns.add(Pair.create(row[1], row[2])); return columns; } }
private void init(){ if (path == null) { throw new TechnicalException("File path can't be NULL!"); } try { parser = new CSVParser(new BufferedReader(new FileReader(new File(path))), strategy); } catch (FileNotFoundException e) { throw Throwables.propagate(e); } if(readHeader) { try { objectCreator.setHeader(parser.getLine()); } catch (IOException e){ throw Throwables.propagate(e); } } }
@Override protected T computeNext() { try { String[] strings = parser.getLine(); if(strings == null) { return endOfData(); } return objectCreator.createObject(strings); } catch (IOException e) { throw Throwables.propagate(e); } }
void add(SolrInputDocument doc, int line, int column, String val) { CSVParser parser = new CSVParser(new StringReader(val), strategy); try { String[] vals = parser.getLine(); if (vals!=null) { for (String v: vals) base.add(doc,line,column,v); } else { base.add(doc,line,column,val); } } catch (IOException e) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,e); } } }
@Override protected Vector computeNext() { String[] line; try { line = parser.getLine(); } catch (IOException e) { throw new IllegalStateException(e); } if (line == null) { return endOfData(); } Vector result = new DenseVector(line.length); for (int i = 0; i < line.length; i++) { result.setQuick(i, Double.parseDouble(line[i])); } return result; }
int r = 0; do { row = parser.getLine(); if (row == null) break;