本文整理汇总了Java中org.supercsv.io.CsvMapReader类的典型用法代码示例。如果您正苦于以下问题:Java CsvMapReader类的具体用法?Java CsvMapReader怎么用?Java CsvMapReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CsvMapReader类属于org.supercsv.io包,在下文中一共展示了CsvMapReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readOneFile
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
@Override
public ImportData readOneFile( File file ) throws IOException, ImportValidationException {
ImportData data = new ImportData();
ImportMetadata im = data.getMetadata();
im.setSourceOfData( new URIImpl( file.toURI().toString() ) );
im.setLegacyMode( true );
try ( Reader rdr = new BufferedReader( new FileReader( file ) ) ) {
mapReader = new CsvMapReader( rdr, CsvPreference.STANDARD_PREFERENCE );
File propfile = propCSVFile( mapReader );
setRdfMapFromFile( propfile ); // will throw an IOException if missing file
createProcessors();
processConceptRelationURIs( data );
processNodePropURIs( data );
processRelationships( data );
}
finally {
if ( null != mapReader ) {
mapReader.close();
}
}
return data;
}
示例2: CSVFile
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
public CSVFile(String fileName){
try{
this.fileName = fileName;
File csvFile = new File(fileName);
// Check whether the file exists
boolean exists = csvFile.exists();
// Creater writer and reader objects
RandomLineAccessFile file = new RandomLineAccessFile(csvFile);
reader = new CsvMapReader(file.getReader(), CsvPreference.STANDARD_PREFERENCE);
writer = new CsvMapWriter(file.getWriter(), CsvPreference.STANDARD_PREFERENCE);
// If the file exists then extract the header and cell processors
if(exists){
header = reader.getCSVHeader(false);
if(header != null)
genProcessors();
}
}catch(Exception e){
e.printStackTrace();
header = null;
}
}
示例3: readFeatureExtractorMaps
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
private Map<String, Map<String, Double>> readFeatureExtractorMaps(CsvMapReader mapReader, List<String> headers,
List<String> featureNames, CellProcessor[] processors) throws IOException {
Map<String, Map<String, Double>> featureMaps = featureNames.stream().collect(
Collectors.toMap(f -> f, f -> new HashMap<String, Double>()));
Map<String, Object> line = readLine(mapReader, headers, processors);
while (line != null) {
for (String featureName : featureNames) {
Map<String, Double> featureMap = featureMaps.get(featureName);
String key = MapFeatureExtractor.toStringKey((int) line.get(deviceId), (DateTime) line.get(timeStamp));
Double value = (Double) line.get(featureName);
featureMap.put(key, value);
}
line = readLine(mapReader, headers, processors);
}
return featureMaps;
}
示例4: readWithCsvMapReader
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
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;
}
示例5: readWithCsvMapReader
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
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;
}
示例6: propCSVFile
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
/**
* Gets the headers for each column and returns the property file. If this
* reader already has a prop file set (from {@link #CSVReader(java.io.File,
* gov.va.semoss.util.UriBuilder, prerna.util.UriBuilder) }, this value from
* the header file is ignored, and the pre-set file is returned in all cases.
*
* @param file the CSV file
*
* @return the control file for the CSV (last column of the header row)
*
* @throws java.io.IOException
*/
private File propCSVFile( CsvMapReader rdr ) throws IOException {
// store the headers of each of the columns
String rawheaders[] = rdr.getHeader( true );
header = new String[rawheaders.length];
// don't copy the last index of the array, because there is no corresponding
// data column (the last column is the control file location)
System.arraycopy( rawheaders, 0, header, 0, header.length - 1 );
// last header in CSV file is the absolute path to the prop file
return ( null == propFile ? new File( rawheaders[rawheaders.length - 1] )
: propFile );
}
示例7: exec
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
@Override
public NodeValue exec(NodeValue csv, NodeValue column) {
if (csv.getDatatypeURI() != null
&& !csv.getDatatypeURI().equals(datatypeUri)
&& !csv.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
LOG.warn("The URI of NodeValue1 MUST be <" + datatypeUri + ">"
+ "or <http://www.w3.org/2001/XMLSchema#string>."
);
}
try {
String sourceCSV = String.valueOf(csv.asNode().getLiteralLexicalForm());
InputStream is = new ByteArrayInputStream(sourceCSV.getBytes("UTF-8"));
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
CsvMapReader mapReader = new CsvMapReader(br, CsvPreference.STANDARD_PREFERENCE);
String header[] = mapReader.getHeader(true);
Map<String, String> row = mapReader.read(header);
String columnName = (String) column.asNode().getLiteralValue();
String value = row.get(columnName);
NodeValue node;
if (value == null) {
node = new NodeValueString("");
} else {
node = new NodeValueString(value);
}
return node;
} catch (Exception ex) {
LOG.debug("No evaluation for " + csv + ", " + column, ex);
throw new ExprEvalException("No evaluation for " + csv + ", " + column, ex);
}
}
示例8: exec
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue csv) {
if (csv.getDatatypeURI() != null
&& !csv.getDatatypeURI().equals(datatypeUri)
&& !csv.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
LOG.warn("The URI of NodeValue1 MUST be <" + datatypeUri + ">"
+ "or <http://www.w3.org/2001/XMLSchema#string>."
);
}
List<NodeValue> nodeValues = new ArrayList<>();
DocumentBuilderFactory builderFactory
= DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
String sourceCSV = String.valueOf(csv.asNode().getLiteralLexicalForm());
InputStream is = new ByteArrayInputStream(sourceCSV.getBytes("UTF-8"));
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
CsvMapReader mapReader = new CsvMapReader(br, CsvPreference.STANDARD_PREFERENCE);
String headers_str[] = mapReader.getHeader(true);
for (String header : headers_str) {
Node node = NodeFactory.createLiteral(header);
NodeValueNode nodeValue = new NodeValueNode(node);
nodeValues.add(nodeValue);
}
return nodeValues;
} catch (Exception ex) {
LOG.debug("No evaluation for " + csv, ex);
throw new ExprEvalException("No evaluation for " + csv, ex);
}
}
示例9: setup
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
@Override
public void setup(OperatorContext context)
{
delimitedParserSchema = new DelimitedSchema(schema);
preference = new CsvPreference.Builder(delimitedParserSchema.getQuoteChar(),
delimitedParserSchema.getDelimiterChar(), delimitedParserSchema.getLineDelimiter()).build();
nameMapping = delimitedParserSchema.getFieldNames().toArray(
new String[delimitedParserSchema.getFieldNames().size()]);
header = StringUtils.join(nameMapping, (char)delimitedParserSchema.getDelimiterChar() + "");
processors = getProcessor(delimitedParserSchema.getFields());
csvStringReader = new ReusableStringReader();
csvMapReader = new CsvMapReader(csvStringReader, preference);
csvBeanReader = new CsvBeanReader(csvStringReader, preference);
}
示例10: init
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
private void init()
{
delimitedParserSchema = new DelimitedSchema(schema);
preference = new CsvPreference.Builder(delimitedParserSchema.getQuoteChar(),
delimitedParserSchema.getDelimiterChar(), delimitedParserSchema.getLineDelimiter()).build();
nameMapping = delimitedParserSchema.getFieldNames()
.toArray(new String[delimitedParserSchema.getFieldNames().size()]);
header = StringUtils.join(nameMapping, (char)delimitedParserSchema.getDelimiterChar() + "");
processors = getProcessor(delimitedParserSchema.getFields());
csvStringReader = new ReusableStringReader();
csvMapReader = new CsvMapReader(csvStringReader, preference);
}
示例11: parse
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
/**
* Parse the given input file. All parsed entries are given to the provided consumer.
*
* @param input
* the input to parse.
* @param consumer
* the consumer for the parsed entries.
*/
void parse(Reader input, Consumer<GeoIpEntry> consumer) throws IOException {
try (CsvMapReader reader = new CsvMapReader(input, STANDARD_PREFERENCE)) {
Map<String, Object> entry;
while ((entry = reader.read(CSV_COLUMNS, cellProcessors)) != null) {
consumer.accept(csvEntryToGeoIpEntry(entry));
}
}
}
示例12: test3
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
public static void test3(RandomLineAccessFile file) throws Exception{
CsvMapReader reader = new CsvMapReader(file.getReader(), CsvPreference.STANDARD_PREFERENCE);
String[] header = reader.getCSVHeader(false);
for(String s : header) System.out.print(s + "|");
System.out.println();
Map<String, String> row;
while((row = reader.read(header)) != null){
for(String data : row.values()) System.out.print(data + "|");
System.out.println();
}
reader.close();
}
示例13: test4
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
public static void test4(RandomLineAccessFile file) throws Exception{
CsvMapReader reader = new CsvMapReader(file.getReader(), CsvPreference.STANDARD_PREFERENCE);
String[] header = reader.getCSVHeader(false);
for(String s : header) System.out.print(s + "|");
System.out.println();
CellProcessor[] processor = new CellProcessor[]{new Optional(), new ParseDouble(), new ParseLong(), new Optional(), new Optional(), new Optional()};
Map<String, ? super Object> row = reader.read(header, processor);
while(row != null && row.size() != 0){
for(Object data : row.values()) System.out.print(data + "|");
row = reader.read(header, processor);
System.out.println();
}
reader.close();
}
示例14: testGetByColumnName
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
@Test
public void testGetByColumnName() throws IOException {
String csv = "John,Connor";
String[] mapping = { "firstName", "lastName" };
CsvMapReader mapReader = new CsvMapReader(new StringReader(csv), STANDARD_PREFERENCE);
Map<String, String> line = mapReader.read(mapping);
Assert.assertNotNull(line);
Assert.assertEquals(2, line.size());
Assert.assertEquals("John", line.get("firstName"));
Assert.assertEquals("Connor", line.get("lastName"));
}
示例15: loadFeatureMetaMap
import org.supercsv.io.CsvMapReader; //导入依赖的package包/类
/**
* Load "feature-metadata" CSV
* @throws IOException
*/
private void loadFeatureMetaMap() throws IOException {
String uri = "/feature-metadata-2013.csv";
try (Reader featIO = new InputStreamReader(GeonamesUtility.class.getResourceAsStream(uri))) {
CsvMapReader featreader = new CsvMapReader(featIO, CsvPreference.EXCEL_PREFERENCE);
String[] columns = featreader.getHeader(true);
Map<String, String> featMap = null;
// Feature Metadata is from Universal Gazetteer
// -----------------------------------
// Feature Designation Code, CODE
// Feature Designation Name, DESC
// Feature Designation Text, -
// Feature Class CLASS
//
while ((featMap = featreader.read(columns)) != null) {
String feat_code = featMap.get("Feature Designation Code");
String desc = featMap.get("Feature Designation Name");
String feat_class = featMap.get("Feature Class");
if (feat_code == null) {
continue;
}
if (feat_code.startsWith("#")) {
continue;
}
features.put(String.format("%s/%s", feat_class, feat_code), desc);
}
featreader.close();
}
}