private static CsvPOJO readWithCsvMapReader(String file) throws Exception { CsvPOJO csvPojo = new CsvPOJO(); Map<String, String> readMap = null; ICsvMapReader mapReader = null; try { mapReader = new CsvMapReader(new FileReader(file), CsvPreference.STANDARD_PREFERENCE); String[] headers = mapReader.getHeader(true); List<CsvRow> rows = new ArrayList<CsvRow>(); while ((readMap = mapReader.read(headers)) != null) { CsvRow row = new CsvRow(); List<String> columns = new ArrayList<String>(); for (String h : headers) { if (!StrUtil.isEmpty(h)) { columns.add(readMap.get(h)); } } row.setCols(columns); rows.add(row); } csvPojo.setHeaders(headers); csvPojo.setRows(rows); } finally { if (mapReader != null) { mapReader.close(); } } return csvPojo; }
private List<CSVRepresentation> parseLines(ICsvMapReader mapReader, String[] headers) throws IOException { List<CSVRepresentation> CSVRepresentations = new ArrayList<>(); final CellProcessor[] processors = getCellProcessorPerColumn(headers); Map<String, Object> beanMap; while ((beanMap = mapReader.read(headers, processors)) != null) { CSVRepresentation CSVRepresentation = convertToRepresentation(beanMap); CSVRepresentations.add(CSVRepresentation); } return CSVRepresentations; }
protected List<Map<String, Object>> readCsvFile(URI fileUrl) { List<Map<String, Object>> result = Lists.newArrayList(); ICsvMapReader mapReader = null; try { mapReader = new CsvMapReader(new FileReader(new File(fileUrl)), CsvPreference.STANDARD_PREFERENCE); // the header columns are used as the keys to the Map String[] headers = getHeaders(); CellProcessor[] processors = getProcessors(); Map<String, Object> contentsMap; while( (contentsMap = mapReader.read(headers, processors)) != null ) { result.add(contentsMap); } } catch (Exception e) { LOGGER.error("Fail to read result file : {}", e.getMessage()); throw new RuntimeException("Fail to read result file."); } finally { if( mapReader != null ) { try { mapReader.close(); } catch (IOException e) {} } } LOGGER.info("Query Result Count : " + result.size()); return result; }
while ((componentMap = mapReader.read(header, rowProcessors)) != null) {
while ((componentMap = mapReader.read(header, rowProcessors)) != null) { String psseId = (String) componentMap.get(header[0]); String rdfId = (String) componentMap.get(header[1]);
while ((componentMap = mapReader.read(header, rowProcessors)) != null) { for (HistoDbAttributeId id : ids) { if (id instanceof HistoDbNetworkAttributeId) { // skip meta data attributes
private JsonNode readCsvFile(URI fileUrl) { ArrayNode resultNode = GlobalObjectMapper.getDefaultMapper().createArrayNode(); ICsvMapReader mapReader = null; try { mapReader = new CsvMapReader(new FileReader(new File(fileUrl)), CsvPreference.STANDARD_PREFERENCE); // the header columns are used as the keys to the Map String[] headers = getHeaders(); CellProcessor[] processors = getProcessors(); Map<String, Object> contentsMap; while( (contentsMap = mapReader.read(headers, processors)) != null ) { LOGGER.debug(String.format("lineNo=%s, rowNo=%s, customerMap=%s", mapReader.getLineNumber(), mapReader.getRowNumber(), contentsMap)); resultNode.add(GlobalObjectMapper.getDefaultMapper().convertValue(contentsMap, JsonNode.class)); } } catch (Exception e) { LOGGER.error("Fail to read result file : {}", e.getMessage()); throw new RuntimeException("Fail to read result file."); } finally { if( mapReader != null ) { try { mapReader.close(); } catch (IOException e) {} } } return resultNode; }
/** * This method reads input stream data values into a map. * * @return Map containing key as field name given by user and value of the field. */ @Override protected Map<String, Object> readData(String[] properties, CellProcessor[] processors) { Map<String, Object> fieldValueMapping = null; try { fieldValueMapping = csvReader.read(properties, processors); } catch (IOException ex) { DTThrowable.rethrow(ex); } return fieldValueMapping; }
final CellProcessor[] rowProcessors = new CellProcessor[headers.length]; Map<String, Object> componentMap; while ((componentMap = csvMapReader.read(headers, rowProcessors)) != null) { String datetime = (String) componentMap.get("datetime"); int forecastTime = (int) Float.parseFloat((String) componentMap.get("forecastTime"));
Map<String, Object> headerMap; DynamicSurveyResponse sr = null; while ((headerMap = reader.read(header, cellProcessors)) != null) {
Map<String, Object> headerMap; SurveyResponse sr = null; while ((headerMap = reader.read(header, cellProcessors)) != null) {
public List<Map<String, Object>> readCsv(String fileName, List<Field> fieldList, int index, int length) { ICsvMapReader mapReader = null; List<Map<String, Object>> returnList = new ArrayList<>(); try { mapReader = new CsvMapReader(new FileReader(fileName) , new CsvPreference.Builder('"', ',', "\r\n") .ignoreEmptyLines(false) .build()); // the header columns are used as the keys to the Map final String[] header = mapReader.getHeader(true); Map<String, Object> rowMap; while( (rowMap = mapReader.read(header, getProcessors(fieldList))) != null && mapReader.getRowNumber() - 1 < index + length + 1) { if(mapReader.getRowNumber() - 1 > index){ returnList.add(rowMap); } } } catch (FileNotFoundException e){ throw new WorkbenchException(CSV_FILE_NOT_FOUND, "CSV File Not Founded.", e); } catch (IOException e){ throw new WorkbenchException(CSV_FILE_NOT_FOUND, "read CSV IOException.", e); } finally { try { if(mapReader != null) mapReader.close(); } catch (Exception e){} } return returnList; }