本文整理汇总了Java中org.supercsv.io.CsvMapReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java CsvMapReader.read方法的具体用法?Java CsvMapReader.read怎么用?Java CsvMapReader.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.supercsv.io.CsvMapReader
的用法示例。
在下文中一共展示了CsvMapReader.read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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();
}
示例3: 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();
}
示例4: 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"));
}
示例5: 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();
}
}
示例6: loadUSStateMetadata
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
* <pre> TODO: This is mildly informed by geonames.org, however even there
* we are still missing a mapping between ADM1 FIPS/ISO codes for a state
* and the Postal codes/abbreviations.
*
* Aliases for the same US province: "US.25" = "MA" = "US.MA" =
* "Massachussetts" = "the Bay State"
*
* Easily mapping the coded data (e.g., 'MA' = '25') worldwide would be
* helpful.
*
* TODO: Make use of geonames.org or other sources for ADM1 postal code
* listings at top level. </pre>
*
* @throws IOException if CSV file not found in classpath
*/
public void loadUSStateMetadata() throws IOException {
String uri = "/us-state-metadata.csv";
try (Reader fio = new InputStreamReader(GeonamesUtility.class.getResourceAsStream(uri))) {
CsvMapReader adm1CSV = new CsvMapReader(fio, CsvPreference.EXCEL_PREFERENCE);
String[] columns = adm1CSV.getHeader(true);
Map<String, String> stateRow = null;
// -----------------------------------
// "POSTAL_CODE","ADM1_CODE","STATE","LAT","LON","FIPS_CC","ISO2_CC"
//
while ((stateRow = adm1CSV.read(columns)) != null) {
String roughID = String.format("%s.%s", stateRow.get("ISO2_CC"), stateRow.get("POSTAL_CODE"));
Place s = new Place(roughID, stateRow.get("STATE"));
s.setFeatureClass("A");
s.setFeatureCode("ADM1");
s.setAdmin1(stateRow.get("ADM1_CODE").substring(2));
s.setCountryCode(stateRow.get("ISO2_CC"));
s.defaultHierarchicalPath();
LatLon yx = GeodeticUtility.parseLatLon(stateRow.get("LAT"), stateRow.get("LON"));
s.setLatLon(yx);
s.setAdmin1PostalCode(stateRow.get("POSTAL_CODE"));
usStateMetadata.add(s);
}
adm1CSV.close();
} catch (Exception err) {
throw new IOException("Could not load US State data" + uri, err);
}
}
示例7: loadExclusions
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
* Exclusions have two columns in a CSV file. 'exclusion', 'category'
*
* "#" in exclusion column implies a comment. Call is responsible for
* getting I/O stream.
*
* @param filestream URL/file with exclusion terms
* @return set of filter terms
* @throws ConfigException if filter is not found
*/
public static Set<String> loadExclusions(InputStream filestream) throws ConfigException {
/*
* Load the exclusion names -- these are terms that are gazeteer
* entries, e.g., gazetteer.name = <exclusion term>, that will be marked
* as search_only = true.
*/
try (Reader termsIO = new InputStreamReader(filestream)) {
CsvMapReader termreader = new CsvMapReader(termsIO, CsvPreference.EXCEL_PREFERENCE);
String[] columns = termreader.getHeader(true);
Map<String, String> terms = null;
HashSet<String> stopTerms = new HashSet<String>();
while ((terms = termreader.read(columns)) != null) {
String term = terms.get("exclusion");
if (StringUtils.isBlank(term) || term.startsWith("#")) {
continue;
}
String trimmed = term.trim();
/* Allow for case-sensitive filtration, if stop terms are listed in native case in resource files */
stopTerms.add(trimmed);
stopTerms.add(trimmed.toLowerCase());
}
termreader.close();
return stopTerms;
} catch (Exception err) {
throw new ConfigException("Could not load exclusions.", err);
}
}
示例8: exec
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
private NodeValue exec(NodeValue csv, NodeValue column, NodeValue quoteChar, NodeValue delimiterChar, NodeValue endOfLineSymbols, NodeValue header) {
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>."
);
}
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"));
String headers_str = "";
if (header.getBoolean()) {
headers_str = br.readLine().split(endOfLineSymbols.asString())[0];
}
CsvPreference prefs = new CsvPreference.Builder(quoteChar.asString().charAt(0), delimiterChar.asString().charAt(0), endOfLineSymbols.asString()).build();
String nodeVal = "none";
if (header.getBoolean()) {
LOG.trace("header is true ");
CsvMapReader mapReader = new CsvMapReader(br, prefs);
Map<String, String> row = mapReader.read(headers_str.split(delimiterChar.asString()));
String columnName = (String) column.asNode().getLiteralValue();
nodeVal = row.get(columnName);
} else {
LOG.trace("header is false");
List<String> values = new CsvListReader(br, prefs).read();
nodeVal = values.get(Integer.valueOf(column.asString()));
}
if (nodeVal != null) {
LOG.trace("return ", nodeVal);
return new NodeValueString(nodeVal);
} else {
LOG.debug("node is null. return nothing");
return new NodeValueString("");
}
} catch (Exception ex) {
LOG.debug("No evaluation for " + csv + ", " + column, ex);
throw new ExprEvalException("No evaluation for " + csv + ", " + column, ex);
}
}
示例9: readLine
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
private Map<String, Object> readLine(CsvMapReader mapReader, List<String> headers, CellProcessor[] processors)
throws IOException {
return mapReader.read(headers.toArray(new String[headers.size()]), processors);
}
示例10: getData
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
public HierarchicalConfiguration getData(final String className,
HierarchicalConfiguration context) {
HierarchicalConfiguration testData = null;
try {
Class<?> clazz = Class.forName(className);
String dataFilePath = null;
URL dataFileURL = null;
String dataFileName = context.getString("supplier.dataFile", null);
log.debug("Checking the data file in argument...");
if (dataFileName == null || dataFileName.equals("")) {
log.debug("Data file not given in argument..Using DataFileFinder..");
dataFilePath = DDUtils.findDataFile(className, ".csv", context);
} else {
log.debug("Got data file in argument");
dataFilePath = dataFileName;
}
log.debug("Data file path: " + dataFilePath);
if (dataFilePath == null) {
return null;// No data found, hence it's a normal test case.
}
dataFileURL = clazz.getResource(dataFilePath);
CsvMapReader reader = new CsvMapReader(new InputStreamReader(dataFileURL.openStream()),
CsvPreference.STANDARD_PREFERENCE);
String list[] = reader.getHeader(true);
Map<String, String> map = null;
testData = new HierarchicalConfiguration();
int i = 0;
while ((map = reader.read(list)) != null) {
String testId = null;
HierarchicalConfiguration newData = new HierarchicalConfiguration();
Set<Map.Entry<String, String>> entrySet = map.entrySet();
for (Map.Entry<String, String> entry : entrySet) {
if (entry.getKey().equals("test-id")) {
newData.addProperty("[@test-id]", entry.getValue());
testId = entry.getValue();
continue;
}
newData.addProperty(entry.getKey(), entry.getValue());
}
testData.addNodes("data(" + i + ")", newData.getRootNode().getChildren());
if (testId != null) {
testData.addProperty("data(" + i + ")[@test-id]", testId);
}
i++;
}
reader.close();
} catch (Exception ex) {
throw new DDException("Error in loading data file", ex);
}
return testData;
}
示例11: main
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File input = new File(args[0]);
System.out.println("Reading from: " + input.getAbsolutePath());
CsvPreference preferences = CsvPreference.STANDARD_PREFERENCE;
CsvMapReader cmr = new CsvMapReader(new FileReader(input), preferences);
Map<String, String> read = cmr.read(new String[] { TIME, SOURCE, DATA });
System.out.println("\"time\",\"M\",\"MHR\",\"FHR\",\"TOCO\",\"QFHR\"");
boolean mark = false;
while (read != null) {
Date time = new Date(Long.parseLong(read.get(TIME)));
byte[] bytes = hex2bytes(read.get(DATA));
String data = bytes2string(bytes);
if (data.length() != bytes.length) {
System.out.println("Length error: String:" + data.length() + " bytes:" + bytes.length);
return;
} else {
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] != (byte) data.charAt(i)) {
System.out.println("***************************** byte: " + bytes[i] + " char: "
+ data.charAt(i));
return;
}
}
}
if (data.equals("MM")) {
mark = true;
} else if (data.startsWith("C")) {
CBlockMessage cb = new CBlockMessage(time, data);
float[] mhr = cb.getMHR();
float[] fhr = cb.getFHR1();
float[] toco = cb.getTOCO();
int[] qfhr = cb.getQFHR1();
for (int i = 0; i < mhr.length; i++) {
System.out.print((time.getTime() + 500) / 1000 + ",");
if (mark) {
System.out.print("10,");
} else {
System.out.print("0,");
}
System.out.print(mhr[i] + ",");
System.out.print(fhr[i] + ",");
System.out.print(toco[i] + ",");
System.out.print(qfhr[i] + "");
System.out.println();
mark = false;
}
} else if (data.startsWith("N02ANS")) {
// System.out.print((time.getTime() + 500) / 1000 + ",");
// int start = "N02ANS".length();
// int fh = Integer.parseInt(data.substring(start, start + 4), 16);
// int n = Integer.parseInt(data.substring(start + 4, start + 8), 16);
// System.out.println(fh + "," + n);
} else {
// StringBuffer sb = new StringBuffer();
// for (int i = 0; i < data.length(); i++) {
// char ch = data.charAt(i);
// if (ch > ' ' && ch < 127)
// sb.append(ch);
// else
// break;
// }
// System.out.println(sb + " [" + data.length() + "]");
}
read = cmr.read(new String[] { TIME, SOURCE, DATA });
}
cmr.close();
}
示例12: readTable
import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
static
public Table<EvaluationRequest> readTable(BufferedReader reader, CsvPreference format) throws IOException {
Table<EvaluationRequest> table = new Table<>();
CsvMapReader parser = new CsvMapReader(reader, format);
String[] header = parser.getHeader(true);
if(header.length > 0 && ("id").equalsIgnoreCase(header[0])){
table.setId(header[0]);
}
List<EvaluationRequest> requests = new ArrayList<>();
while(true){
Map<String, String> arguments = parser.read(header);
if(arguments == null){
break;
}
String id = arguments.remove(table.getId());
EvaluationRequest request = new EvaluationRequest(id);
request.setArguments(arguments);
requests.add(request);
}
parser.close();
table.setRows(requests);
return table;
}