private List<String> read(CsvListReader reader) throws CsvImportException { try { return reader.read(); } catch (IOException e) { throw new ReadValuesException(this, e); } }
public static List<String> parseHintedHandoffEnabledDCs(final String dcNames) throws IOException { final CsvListReader csvListReader = new CsvListReader(new StringReader(dcNames), STANDARD_SURROUNDING_SPACES_NEED_QUOTES); return csvListReader.read(); }
CsvListReader reader = new CsvListReader(new FileReader(inputCsv), CsvPreference.STANDARD_PREFERENCE); CsvListWriter writer = new CsvListWriter(new FileWriter(outputCsv), CsvPreference.STANDARD_PREFERENCE); List<String> columns; while ((columns = reader.read()) != null) { System.out.println("Input: " + columns); // Add new columns columns.add(1, "Column_2"); columns.add("Last_column"); System.out.println("Output: " + columns); writer.write(columns); } reader.close(); writer.close();
static private boolean checkFormat(BufferedReader reader, CsvPreference format) throws IOException { CsvListReader parser = new CsvListReader(reader, format){ @Override public void close(){ } }; int columns = 0; // Check the header line and the first ten lines for(int line = 0; line < (1 + 10); line++){ List<String> row = parser.read(); if(row == null){ break; } int rowColumns = row.size(); if((rowColumns > 1) && (columns == 0 || columns == rowColumns)){ columns = rowColumns; } else { return false; } } parser.close(); return (columns > 1); }
while ((record = reader.read()) != null) {
private void readRow() { if (writer != null && row != null) { // flush the current row to the writer, before advancing try { writer.write(row); } catch (IOException e) { throw new PaxmlRuntimeException("Cannot write to shadow csv file: " + writerFile.getAbsolutePath(), e); } } try { row = reader.read(); } catch (IOException e) { throw new PaxmlRuntimeException("Cannot read next line from csv file: " + getResourceIdentifier(), e); } }
while ((record = reader.read()) != null) { SamplerRecord value = new SamplerRecord(record); values.add(value);
public static String addTimestampColumnFromCsv(String timeStr, String inputPath, String outputPath) { File inputFile = new File(inputPath); File outputFile = new File(outputPath); CsvListReader reader = null; CsvListWriter writer = null; try { CsvPreference csvPreference = new CsvPreference.Builder('"', ',', "\r\n") .ignoreEmptyLines(false) .build(); reader = new CsvListReader(new FileReader(inputFile), csvPreference); writer = new CsvListWriter(new FileWriter(outputFile), csvPreference); List<String> columns; while ((columns = reader.read()) != null) { columns.add(timeStr); writer.write(columns); } } catch (IOException e) { throw new MetatronException("Fail to transform csv file :" + e.getMessage()); } finally { try { if (reader != null) reader.close(); if (writer != null) writer.close(); } catch (IOException e) {} } return outputFile.getAbsolutePath(); }