List of usage examples for org.apache.commons.csv CSVFormat DEFAULT
CSVFormat DEFAULT
To view the source code for org.apache.commons.csv CSVFormat DEFAULT.
Click Source Link
From source file:ca.liquidlabs.android.speedtestvisualizer.util.CsvDataParser.java
/** * Parses CSV data//from w ww. j av a2 s. c om * * @param csvHeader Header items for csv records * @param csvData * @return */ public static List<SpeedTestRecord> parseCsvData(String csvHeader, String csvData) { Reader in = new StringReader(getCsvData(csvHeader, csvData)); try { CSVParser parser = new CSVParser(in, CSVFormat.DEFAULT.toBuilder().withHeader().build()); // get the parsed records List<CSVRecord> list = parser.getRecords(); // create a list to convert data into SpeedTestRecord model List<SpeedTestRecord> speedTestRecords = new ArrayList<SpeedTestRecord>(); for (CSVRecord csvRecord : list) { speedTestRecords.add(new SpeedTestRecord(csvRecord)); } return speedTestRecords; } catch (IOException e) { Tracer.error(LOG_TAG, e); } // when no data, send empty list return Collections.emptyList(); }
From source file:com.leadscope.commanda.DefaultCommandaArgs.java
public static CommandaArgs defaultArgs() { return new CommandaArgs(defaultSource, Arrays.asList(defaultSource, new CSVSource("csv", "Default CSV format with UTF-8 encoding", CSVFormat.DEFAULT, Charset.forName("UTF-8")), new CSVSource("tab", "Tab-delimited CSV format with UTF-8 encoding", CSVFormat.DEFAULT.withDelimiter('\t'), Charset.forName("UTF-8")), new ToxmlSource()), Arrays.asList(//from ww w. ja va 2 s .c o m new LambdaElementMap(DefaultLambdaImports.imports, DefaultLambdaImports.staticImports, "s->s", STRING_TYPE, STRING_TYPE), new LambdaStreamMap(DefaultLambdaImports.imports, DefaultLambdaImports.staticImports, "in->in", STRING_TYPE, STRING_TYPE), new LambdaModifier(DefaultLambdaImports.imports, DefaultLambdaImports.staticImports, "s->{}", STRING_TYPE), new CSVLineMap("csvlines", "Maps lists of strings into CSV lines", CSVFormat.DEFAULT), new CSVLineMap("tablines", "Maps lists of strings into tab-delimited lines", CSVFormat.DEFAULT.withDelimiter('\t'))), Arrays.asList(new ToxmlSink())); }
From source file:com.github.terma.gigaspacewebconsole.server.CsvExecuteResponseStream.java
public CsvExecuteResponseStream(final Writer writer) throws IOException { this.csvPrinter = CSVFormat.DEFAULT.print(writer); }
From source file:com.denimgroup.threadfix.csv2ssl.parser.CSVToSSVLParser.java
public static String parse(Reader reader, String... format) { try {/* ww w. ja v a 2s .c o m*/ CSVParser parse = CSVFormat.DEFAULT.withSkipHeaderRecord(CONFIG.shouldSkipFirstLine).withHeader(format) .parse(reader); return RecordToXMLSerializer.getFromReader(parse); } catch (IOException e) { throw new IllegalStateException("Received IOException while parsing file.", e); } }
From source file:com.hurence.logisland.processor.TimeSeriesCsvLoader.java
/** * CSV reader that waits for a 2 columns csv files with or without a header. * If less than 2 columns ==> exception, otherwise, the 3rd and following columns are ignored * * @param in// ww w . j a va 2s . c om * @param hasHeader * @param inputDatetimeFormat input date format * @return * @throws IOException * @throws IllegalArgumentException * @throws ArrayIndexOutOfBoundsException */ public static List<Record> load(Reader in, boolean hasHeader, DateTimeFormatter inputDatetimeFormat) throws IOException { List<Record> records = new ArrayList<>(); for (CSVRecord record : CSVFormat.DEFAULT.parse(in)) { try { if (!hasHeader) { StandardRecord event = new StandardRecord("sensors"); event.setField(TIMESTAMP_KEY, FieldType.LONG, inputDatetimeFormat.withZone(DateTimeZone.UTC) .parseDateTime(record.get(0)).getMillis()); event.setField(VALUE_KEY, FieldType.DOUBLE, Double.parseDouble(record.get(1))); records.add(event); } else { TIMESTAMP_KEY = record.get(0); VALUE_KEY = record.get(1); } hasHeader = false; } catch (Exception e) { logger.error("Parsing error " + e.getMessage()); throw new RuntimeException("parsing error", e); } } return records; }
From source file:io.scigraph.services.jersey.writers.CsvWriter.java
@Override CSVPrinter getCsvPrinter(Writer writer) throws IOException { return new CSVPrinter(writer, CSVFormat.DEFAULT); }
From source file:com.github.jferard.pgloaderutils.loader.CSVLoaderHelper.java
public CSVFormat getCSVFormat(char delimiter, char quote, char escape) { CSVFormat format = CSVFormat.DEFAULT.withDelimiter(delimiter).withQuote(quote); if (escape != quote) format.withEscape(escape);//ww w . ja va 2s . c om return format; }
From source file:com.esri.geoevent.datastore.CSVParsingTest.java
@Test public void testSimpleCSVParse() throws Exception { StringReader csvServers = new StringReader("mingz14,getest1w"); Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(csvServers); for (CSVRecord record : records) { int size = record.size(); for (int i = 0; i < size; i++) { System.out.println(record.get(i)); }/*ww w . jav a2 s .co m*/ } }
From source file:functions.LoadCSVdata.java
public void LoadFeeDataToJTable(JTable t, String path) { try {/*from w w w. ja v a 2s. c om*/ file = new File(path); parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT); DefaultTableModel model = (DefaultTableModel) t.getModel(); model.setRowCount(0); for (CSVRecord c : parser) { if (c.getRecordNumber() == 1) continue; model.addRow( new Object[] { c.get(datatype.GlobalVariable.TYPE), c.get(datatype.GlobalVariable.AMOUNT), c.get(datatype.GlobalVariable.PAID_BY), c.get(datatype.GlobalVariable.PAYER) }); } } catch (Exception e) { System.out.println(e); } }
From source file:Client.Message.java
public Message(String message) throws IOException { this.message = message; Reader in = new StringReader(message); CSVParser parser = new CSVParser(in, CSVFormat.DEFAULT); List<CSVRecord> list = parser.getRecords(); type = MessageType.valueOf(list.get(0).toString()); author = list.get(1).toString();//from www . j a v a 2s .c om if (type == MessageType.TEXT) { text = list.get(2).toString(); } }