Tabnine Logo
CsvMapReader
Code IndexAdd Tabnine to your IDE (free)

How to use
CsvMapReader
in
org.supercsv.io

Best Java code snippets using org.supercsv.io.CsvMapReader (Showing top 20 results out of 315)

origin: bill1012/AdminEAP

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;
}
origin: openscoring/openscoring

static
public TableEvaluationRequest readTable(BufferedReader reader, CsvPreference format) throws IOException {
  CsvMapReader parser = new CsvMapReader(reader, format);
  String[] header = parser.getHeader(true);
  List<String> columns = Arrays.asList(header);
  TableEvaluationRequest tableRequest = new TableEvaluationRequest()
    .setColumns(columns);
  String idColumn = tableRequest.getIdColumn();
  List<EvaluationRequest> requests = new ArrayList<>();
  while(true){
    Map<String, String> row = parser.read(header);
    if(row == null){
      break;
    }
    String id = null;
    if(idColumn != null){
      id = row.remove(idColumn);
    }
    EvaluationRequest request = new EvaluationRequest(id)
      .setArguments(row);
    requests.add(request);
  }
  tableRequest.setRequests(requests);
  parser.close();
  return tableRequest;
}
origin: org.wikibrainapi/wikibrain-spatial

/**
 * TODO: keep track of duplicate or missing keys with special status codes
 * @param shapeFile
 * @return
 * @throws IOException
 */
private Map<String, MappingInfo> readExisting(WikiBrainShapeFile shapeFile) throws IOException {
  HashMap<String, MappingInfo> mapping = new HashMap<String, MappingInfo>();
  if (!shapeFile.hasMappingFile()) {
    return mapping;
  }
  CsvMapReader reader = new CsvMapReader(
      WpIOUtils.openBufferedReader(shapeFile.getMappingFile()),
      CsvPreference.STANDARD_PREFERENCE
  );
  String [] header = reader.getHeader(true);
  while (true) {
    Map<String, String> row = reader.read(header);
    if (row == null) {
      break;
    }
    MappingInfo info = new MappingInfo(row);
    if (!info.isUnknown()) {
      mapping.put(info.key, info);
    }
  }
  return mapping;
}
origin: OpenSextant/opensextant

int linenum = 0;
String[] columns = in.getHeader(true);
Map<String, String> testRow = null;
while ((testRow = in.read(columns)) != null) {
origin: apache/apex-malhar

/**
 * Extracts the fields from a delimited record and returns a map containing
 * field names and values
 */
@Override
Map<String, Object> extractFields(String line)
{
 if (!initialized) {
  init();
  initialized = true;
 }
 if (StringUtils.isBlank(line) || StringUtils.equals(line, header)) {
  return null;
 }
 try {
  csvStringReader.open(line);
  return csvMapReader.read(nameMapping, processors);
 } catch (IOException e) {
  logger.error("Error parsing line{} Exception {}", line, e.getMessage());
  return null;
 }
}
origin: org.apache.apex/malhar-contrib

@Override
public void teardown()
{
 try {
  csvMapReader.close();
 } catch (IOException e) {
  logger.error("Error while closing csv map reader {}", e.getMessage());
  DTThrowable.wrapIfChecked(e);
 }
 try {
  csvBeanReader.close();
 } catch (IOException e) {
  logger.error("Error while closing csv bean reader {}", e.getMessage());
  DTThrowable.wrapIfChecked(e);
 }
}
origin: shilad/wikibrain

/**
 * TODO: keep track of duplicate or missing keys with special status codes
 * @param shapeFile
 * @return
 * @throws IOException
 */
private Map<String, MappingInfo> readExisting(WikiBrainShapeFile shapeFile) throws IOException {
  HashMap<String, MappingInfo> mapping = new HashMap<String, MappingInfo>();
  if (!shapeFile.hasMappingFile()) {
    return mapping;
  }
  CsvMapReader reader = new CsvMapReader(
      WpIOUtils.openBufferedReader(shapeFile.getMappingFile()),
      CsvPreference.STANDARD_PREFERENCE
  );
  String [] header = reader.getHeader(true);
  while (true) {
    Map<String, String> row = reader.read(header);
    if (row == null) {
      break;
    }
    MappingInfo info = new MappingInfo(row);
    if (!info.isUnknown()) {
      mapping.put(info.key, info);
    }
  }
  return mapping;
}
origin: org.apache.apex/malhar-contrib

/**
 * Extracts the fields from a delimited record and returns a map containing
 * field names and values
 */
@Override
Map<String, Object> extractFields(String line)
{
 if (!initialized) {
  init();
  initialized = true;
 }
 if (StringUtils.isBlank(line) || StringUtils.equals(line, header)) {
  return null;
 }
 try {
  csvStringReader.open(line);
  return csvMapReader.read(nameMapping, processors);
 } catch (IOException e) {
  logger.error("Error parsing line{} Exception {}", line, e.getMessage());
  return null;
 }
}
origin: apache/apex-malhar

@Override
public void teardown()
{
 try {
  csvMapReader.close();
 } catch (IOException e) {
  logger.error("Error while closing csv map reader {}", e.getMessage());
  DTThrowable.wrapIfChecked(e);
 }
 try {
  csvBeanReader.close();
 } catch (IOException e) {
  logger.error("Error while closing csv bean reader {}", e.getMessage());
  DTThrowable.wrapIfChecked(e);
 }
}
origin: OpenSextant/opensextant

/**
 * Create a typical CSV writer -- Excel compliant
 *
 * @param file
 * @return
 * @throws IOException
 */
public CsvMapReader open(String file) throws IOException {
  InputStreamReader rdr = FileUtility.getInputStream(file, "UTF-8");
  CsvMapReader R = new CsvMapReader(rdr, CsvPreference.STANDARD_PREFERENCE);
  return R;
}
origin: org.wikibrainapi/wikibrain-spatial

  throw new IOException("No mapping file found: " + getMappingFile());
CsvMapReader reader = new CsvMapReader(
    WpIOUtils.openBufferedReader(getMappingFile()),
    CsvPreference.STANDARD_PREFERENCE
String [] header = reader.getHeader(true);
while (true) {
  Map<String, String> row = reader.read(header);
  if (row == null) {
    break;
origin: org.apache.apex/malhar-contrib

if (parsedOutput.isConnected()) {
 csvStringReader.open(incomingString);
 Map<String, Object> map = csvMapReader.read(nameMapping, processors);
 parsedOutput.emit(map);
 parsedOutputCount++;
origin: apache/apex-malhar

/**
 * This method creates an instance of csvMapReader.
 *
 * @param reader
 * @param preference
 * @return CSV Map Reader
 */
@Override
protected ICsvMapReader getReader(ReusableStringReader reader, CsvPreference preference)
{
 csvReader = new CsvMapReader(reader, preference);
 return csvReader;
}
origin: shilad/wikibrain

  throw new IOException("No mapping file found: " + getMappingFile());
CsvMapReader reader = new CsvMapReader(
    WpIOUtils.openBufferedReader(getMappingFile()),
    CsvPreference.STANDARD_PREFERENCE
String [] header = reader.getHeader(true);
while (true) {
  Map<String, String> row = reader.read(header);
  if (row == null) {
    break;
origin: apache/apex-malhar

if (parsedOutput.isConnected()) {
 csvStringReader.open(incomingString);
 Map<String, Object> map = csvMapReader.read(nameMapping, processors);
 parsedOutput.emit(map);
 parsedOutputCount++;
origin: metatron-app/metatron-discovery

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;
}
origin: itesla/ipst

public static Map<String, String> readWithCsvMapReader(Path dicoFile) throws Exception {
  try (ICsvMapReader mapReader = new CsvMapReader(Files.newBufferedReader(dicoFile, StandardCharsets.UTF_8), CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE)) {
    final String[] header = mapReader.getHeader(true);
    LOGGER.debug(" cvsheader length: " + header.length);
origin: itesla/ipst

private Map<String, String> readWithCsvMapReader(Path mappingFile) throws IOException {
  Map<String, String> retMap = new HashMap<>();
  try (ICsvMapReader mapReader = new CsvMapReader(Files.newBufferedReader(mappingFile, StandardCharsets.UTF_8), CsvPreference.STANDARD_PREFERENCE)) {
    final String[] header = mapReader.getHeader(true);
    log.info(" cvsheader length: " + header.length);
origin: itesla/ipst

private static void parseCsv(InputStream is, Set<HistoDbAttributeId> ids, Table<Integer, String, Float> hdTable, int expectedRowCount) throws IOException {
  int rowcount = 0;
  try (ICsvMapReader mapReader = new CsvMapReader(new InputStreamReader(is), new CsvPreference.Builder('"', ',', "\r\n").build())) {
origin: metatron-app/metatron-discovery

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;
}
org.supercsv.ioCsvMapReader

Javadoc

CsvMapReader reads each CSV row into a Map with the column name as the map key, and the column value as the map value.

Most used methods

  • <init>
    Constructs a new CsvMapReader with the supplied (custom) Tokenizer and CSV preferences. The tokenize
  • read
  • getHeader
  • close
  • executeProcessors
  • getColumns
  • readRow

Popular in Java

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (Timer)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • compareTo (BigDecimal)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now