org.supercsv.io.ICsvMapReader Java Examples

The following examples show how to use org.supercsv.io.ICsvMapReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DtaParser.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public static Map<String, String> readWithCsvMapReader(Path dicoFile) throws Exception {

        Map<String, String> retMap = new HashMap<>();
        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);
            final CellProcessor[] rowProcessors = new CellProcessor[header.length];
            for (int i = 0; i < rowProcessors.length; i++) {
                if (i == 0) {
                    rowProcessors[i] = new NotNull();
                } else {
                    rowProcessors[i] = null;
                }
            }

            Map<String, Object> componentMap;
            while ((componentMap = mapReader.read(header, rowProcessors)) != null) {
                //System.out.println(String.format("lineNo=%s, rowNo=%s, mapping=%s", mapReader.getLineNumber(), mapReader.getRowNumber(), customerMap));
                String eurostagId = (String) componentMap.get(header[1]);
                String cimId = (String) componentMap.get(header[0]);
                if (eurostagId == null) {
                    LOGGER.warn("eurostagId=" + eurostagId + ", cimId=" + cimId);
                } else {
                    if (retMap.containsKey(eurostagId)) {
                        LOGGER.warn("eurostagId=" + eurostagId + " already in the map");
                    }
                    retMap.put(eurostagId, cimId);
                }
            }
        }

        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("ids map: " + retMap);
        }
        return retMap;

    }
 
Example #2
Source File: DdbDyrLoader.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
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);
        final CellProcessor[] rowProcessors = new CellProcessor[header.length];
        for (int i = 0; i < rowProcessors.length; i++) {
            if (i == 0) {
                rowProcessors[i] = new NotNull();
            } else {
                rowProcessors[i] = new NotNull();
            }
        }

        Map<String, Object> componentMap;
        while ((componentMap = mapReader.read(header, rowProcessors)) != null) {
            String psseId = (String) componentMap.get(header[0]);
            String rdfId = (String) componentMap.get(header[1]);
            if (psseId == null) {
                log.warn("psseId=" + psseId + ", rdfId=" + rdfId);
            } else {
                if (retMap.containsKey(psseId)) {
                    log.warn("psseId=" + psseId + " already in the map");
                }
                retMap.put(psseId, rdfId);
            }
        }
    }

    if (log.isTraceEnabled()) {
        log.trace("ids map: " + retMap);
    }
    log.info("ids map: " + retMap);
    return retMap;
}
 
Example #3
Source File: CSVParserTest.java    From attic-apex-malhar with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}