当前位置: 首页>>代码示例>>Java>>正文


Java CSVParser类代码示例

本文整理汇总了Java中au.com.bytecode.opencsv.CSVParser的典型用法代码示例。如果您正苦于以下问题:Java CSVParser类的具体用法?Java CSVParser怎么用?Java CSVParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CSVParser类属于au.com.bytecode.opencsv包,在下文中一共展示了CSVParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCSVFile

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public List<InterpolatedDoublesCurve> parseCSVFile(URL fileUrl) {
  ArgumentChecker.notNull(fileUrl, "fileUrl");
  
  final List<InterpolatedDoublesCurve> curves = Lists.newArrayList();
  CSVDocumentReader csvDocumentReader = new CSVDocumentReader(fileUrl, CSVParser.DEFAULT_SEPARATOR, 
      CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER, new FudgeContext());
  
  List<FudgeMsg> rowsWithError = Lists.newArrayList();
  for (FudgeMsg row : csvDocumentReader) {
    try {
      curves.add( createCurve(row));
    } catch (Exception ex) {
      ex.printStackTrace();
      rowsWithError.add(row);
    }
  }
  
  s_logger.warn("Total unprocessed rows: {}", rowsWithError.size());
  for (FudgeMsg fudgeMsg : rowsWithError) {
    s_logger.warn("{}", fudgeMsg);
  }
  return curves;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:IRCurveParser.java

示例2: initializeFromStream

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * @param is The input stream to load
 */
public void initializeFromStream(InputStream is) throws IOException {
  CSVParser parser = new CSVParser();
  BufferedReader r = new BufferedReader(new InputStreamReader(is));
  String line = r.readLine();
  while (line != null) {
    String[] fields = parser.parseLine(line);
    if (fields.length != 3) {
      s_logger.warn("Line {} not in proper format.", line);
    } else {
      String scheme = fields[0];
      String id = fields[1];
      String normalization = fields[2];
      addSubscription(ExternalId.of(scheme, id), normalization);
      try {
        Thread.sleep(200L);
      } catch (InterruptedException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
      }
    }
    line = r.readLine();
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:PeriodicLiveDataTimeSeriesStorageServer.java

示例3: getList

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * Helper to convert comma separated string into list
 * @param tokenizedList
 * @return
 */
private List<String> getList(final String tokenizedList){
	List<String> list = null;
	
	if(tokenizedList != null){
		list = new ArrayList<String>();
		CSVParser parser = new CSVParser();
		try {
			String[]  tokens = parser.parseLine(tokenizedList);
			for(String contributor: tokens){
				list.add(contributor.trim());
			}
		}catch (IOException e) {
			logger.error("Problem parsing list", e);
		}
	}
	
	return list;
}
 
开发者ID:robertzak,项目名称:goodreads-parser,代码行数:24,代码来源:GoodReadsParsingService.java

示例4: CsvStreamReader

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * Creates a CsvStreamReader with supplied separator and quote char.
 *
 * @param source The file to an underlying CSV source
 * @param separator The delimiter to use for separating entries
 * @param quoteChar The character to use for quoted elements
 * @param escape The character to use for escaping a separator or quote
 * @param line The line number to skip for start reading
 * @param strictQuotes Sets if characters outside the quotes are ignored
 * @param ignoreLeadingWhiteSpace If true, parser should ignore
 *  white space before a quote in a field
 */
private CsvStreamReader(Source source, char separator, char quoteChar,
    char escape, int line, boolean strictQuotes,
    boolean ignoreLeadingWhiteSpace) {
  super(new StringReader("")); // dummy call to base constructor
  contentQueue = new ArrayDeque<>();
  TailerListener listener = new CsvContentListener(contentQueue);
  tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY,
      false, true, 4096);
  this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes,
      ignoreLeadingWhiteSpace);
  this.skipLines = line;
  try {
    // wait for tailer to capture data
    Thread.sleep(DEFAULT_MONITOR_DELAY);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:CsvStreamReader.java

示例5: CSV

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public CSV(String csvfile) {
	super();

	this.setFilename(csvfile);
	FileInputStream fs = null;
	BufferedReader br = null;

	this.parser = new CSVParser(',', '"');

	try {
		this.keys = new ArrayList<String>();
		setData(new DataSource());

		fs = new FileInputStream(csvfile);
		br = new BufferedReader(new InputStreamReader(fs));
		this.findKeys(br);
		this.createData(br);
	} catch (Exception e) {
		log.severe(e.getMessage());
	}
}
 
开发者ID:sugarcrm,项目名称:candybean,代码行数:22,代码来源:CSV.java

示例6: CSVInput

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public CSVInput(InputStream ins) throws IOException {
    in = new CSVReader( new InputStreamReader(ins, StandardCharsets.UTF_8), CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, '\0' );
    
    String[] headerLine = in.readNext();
    if (headerLine == null) {
        throw new EpiException("No data, cannot read header line");
    }
    headers = new String[headerLine.length];
    for(int i = 0; i < headerLine.length; i++) {
        headers[i] = safeColName( headerLine[i].trim() );
    }
    lineNumber++;
    if (headerLine.length > 1 && headerLine[0].equals("#")) {
        hasPreamble = true;
    }
}
 
开发者ID:epimorphics,项目名称:dclib,代码行数:17,代码来源:CSVInput.java

示例7: InitLocalDataBaseAsyncTask

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public InitLocalDataBaseAsyncTask(Context context)
{
    _context = context;
    _csvParser = new CSVParser('\t');

    // get the total CSV assets file size.
    try {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(_context.getAssets().open(SIZE_INDEX_FILE), "UTF-8"));

        // do reading, usually loop until end of file reading
        String sizeStr = reader.readLine();
        Log.d("###", "sizeStr="+sizeStr);
        _totalDataLength = Long.parseLong(sizeStr);
        reader.close();
    }
    catch (IOException e)
    {
        Log.e("###", "Could not read file: " + SIZE_INDEX_FILE );
    }
}
 
开发者ID:dipdowel,项目名称:tatoeba-android,代码行数:22,代码来源:InitLocalDataBaseAsyncTask.java

示例8: getRecentFiles

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public static Stream<Path> getRecentFiles() {
    try {
        String raw = PREFERENCES.get("recentFiles", "");
        /*
         * Use non-default constructor to set strictQuotes. This works
         * around a bug in the case that a single field is read with quotes
         * around it, eg "mypath". On decode the second quote is treated as
         * part of the string, so the result is the invalid `mypath"'
         */
        CSVParser parser = new CSVParser(
                CSVParser.DEFAULT_SEPARATOR,
                CSVParser.DEFAULT_QUOTE_CHARACTER,
                CSVParser.DEFAULT_ESCAPE_CHARACTER,
                true);

        return Stream.of(parser.parseLine(raw))
                .filter(string -> !string.isEmpty())
                .map(Paths::get)
                .filter(Files::exists);
    } catch (IOException ex) {
        LOG.log(Level.WARNING, null, ex);
        return Stream.empty();
    }
}
 
开发者ID:fuzzyBSc,项目名称:systemdesign,代码行数:25,代码来源:RecentFiles.java

示例9: processResponseDocumentContent

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
@Transactional
private void processResponseDocumentContent(String content, Integer orderId, Integer projectId) throws Exception {
    BufferedReader reader = new BufferedReader(new StringReader(content));
    String line;
    String[] toks;
    CSVParser parser = new CSVParser();
    int counter = 1;
    reader.readLine();  //skip the first line which is a header.
    while ((line = reader.readLine()) != null) {
        counter++;
        line = line.trim();
        if (line.length() <= 0) continue;
        try {
            toks = parser.parseLine(line);

            if (toks.length != 4) {
                throw new RuntimeException("Invalid number of columns in row " + counter);
            }

            updateTranslation(orderId, new Long(toks[0]), toks[1], toks[2], toks[3]);
        } catch (Exception e) {
            logger.error("Invalid line: " + line + " (" + e.getMessage() + ")");
            throw new RuntimeException("Invalid line: " + line + " (" + e.getMessage() + ")");
        }
    }
}
 
开发者ID:qcri-social,项目名称:AIDR,代码行数:27,代码来源:TWBTranslationServiceImpl.java

示例10: initParserOnly

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * Only initialize enough stuff in order to parse rows and construct instances
 *
 * @param attNames the names of the attributes to use
 */
public void initParserOnly(List<String> attNames) {
  char encl = m_Enclosures.charAt(0);
  if (encl == '\\' && m_Enclosures.length() == 2) {
    encl = m_Enclosures.charAt(1);
  }
  m_parser = new CSVParser(m_FieldSeparator.charAt(0), encl, '\\');

  m_attributeNames = attNames;
  if (attNames != null) {
    processRanges(attNames.size(), TYPE.UNDETERMINED);
    processNominalSpecs(attNames.size());
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:19,代码来源:CSVToARFFHeaderMapTask.java

示例11: loadExchangeData

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * Loads the exchange data
 * 
 * @param filename  the filename, not null
 */
private void loadExchangeData() {
  InputStream is = getClass().getResourceAsStream(EXCHANGE_ISO_FILE);
  if (is == null) {
    throw new OpenGammaRuntimeException("Unable to locate " + EXCHANGE_ISO_FILE);
  }
  CSVReader exchangeIsoReader = new CSVReader(new InputStreamReader(is), CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER, 1);
  String [] nextLine;
  try {
    while ((nextLine = exchangeIsoReader.readNext()) != null) {
      String micCode = nextLine[0];
      String description = nextLine[1];
      String countryCode = nextLine[2];
      String country = nextLine[3];
      String city = nextLine[4];
      String acr = nextLine[5];
      String status = nextLine[7];
      if (StringUtils.isNotBlank(micCode) && StringUtils.isNotBlank(countryCode)) {
        Exchange exchange = new Exchange();
        exchange.setMic(micCode);
        exchange.setDescription(description);
        exchange.setCountryCode(countryCode);
        exchange.setCountry(country);
        exchange.setCity(city);
        exchange.setAcr(acr);
        exchange.setStatus(status);
        _exchangeMap.put(micCode, exchange);
        _exchangeDescriptionMap.put(description.toUpperCase(), exchange);
      }
    }
    exchangeIsoReader.close();
  } catch (IOException e) {
    throw new OpenGammaRuntimeException("Unable to read from " + EXCHANGE_ISO_FILE, e);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:40,代码来源:DefaultExchangeDataProvider.java

示例12: exportReport

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public void exportReport(EvalEvaluation evaluation, String groupIds, String evaluateeId, OutputStream outputStream, String exportType) {
	String[] groupIdsArray = new String [] {};
	CSVParser parser= new CSVParser();
	if (groupIds != null) {
		try {
			groupIdsArray = parser.parseLine(groupIds);
		} catch (IOException e) {
			//Is fine if this happens, empty array still
		}
	}
	exportReport(evaluation,groupIdsArray,evaluateeId,outputStream,exportType);
}
 
开发者ID:sakaicontrib,项目名称:evaluation,代码行数:13,代码来源:ReportExporterBean.java

示例13: parse

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
public void parse(Reader fileReader, String fileType, LogRecordCollector collector) throws IOException {
  try (CSVReader csvReader = new CSVReader(
      fileReader,
      config.getDelimiter(),
      CSVParser.DEFAULT_QUOTE_CHARACTER,
      CSVParser.NULL_CHARACTER);) {

    long line = 0;

    String[] headers = csvReader.readNext();
    line++;
    String[] fieldNames = constructFieldNames(headers, fileType, config.isCleanKeysForES());

    String[] record = null;
    while ((record = csvReader.readNext()) != null) {
      if (record.length != headers.length) {
        // unmatched record length
        LOGGER.warn("Unmatched record column count detected at line {} - header: {} record: {}",
            line, headers.length, record.length);
        continue;
      }
      LogRecord logRecord = new LogRecord();
      for (int i = 0; i < fieldNames.length; i++) {
        if (config.isSkipBlankFields() && StringUtils.isBlank(record[i])) {
          // skip
        } else {
          String value = config.isTrimFieldValue() ? StringUtils.trim(record[i]) : record[i];
          logRecord.setValue(fieldNames[i], value);
        }
      }
      collector.emit(logRecord);
    }
  }
}
 
开发者ID:boozallen,项目名称:cognition,代码行数:35,代码来源:CsvLogRecordParser.java

示例14: getStrings

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public String[] getStrings(String name) {
    String[] rv = null;
    // get the count
    int count = getInt(name + ".count", -1);
    if (count == 0) {
        // zero count means empty array
        rv = new String[0];
    } else if (count > 0) {
        rv = new String[count];
        for (int i = 1; i <= count; i++)
        {
            rv[i - 1] = getString(name + "." + i, "");
        }
        // store the array in the properties
        this.addConfigItem(new ConfigItemImpl(name, rv, TYPE_ARRAY, SOURCE_GET_STRINGS), SOURCE_GET_STRINGS);
    } else {
        if (findConfigItem(name, null) != null) {
            // the config name exists
            String value = getString(name);
            if (StringUtils.isBlank(value)) {
                // empty value is an empty array
                rv = new String[0];
                this.addConfigItem(new ConfigItemImpl(name, rv, TYPE_ARRAY, SOURCE_GET_STRINGS), SOURCE_GET_STRINGS);
            } else {
                CSVParser csvParser = new CSVParser(',','"','\\',false,true); // should configure this for default CSV parsing
                try {
                    rv = csvParser.parseLine(value);
                    this.addConfigItem(new ConfigItemImpl(name, rv, TYPE_ARRAY, SOURCE_GET_STRINGS), SOURCE_GET_STRINGS);
                } catch (IOException e) {
                    log.warn("Config property ("+name+") read as multi-valued string, but failure occurred while parsing: "+e, e);
                }
            }
        }
    }
    return rv;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:40,代码来源:BasicConfigurationService.java

示例15: parseAdditionalContributors

import au.com.bytecode.opencsv.CSVParser; //导入依赖的package包/类
/**
 * 
 * @param addContStr
 * @return
 */
private List<Contributor> parseAdditionalContributors(final String addContStr){
	List<Contributor> contributors = null;
	
	if(addContStr != null){
		contributors = new ArrayList<Contributor>();
		CSVParser parser = new CSVParser();
		try {
			String[]  tokens = parser.parseLine(addContStr);
			for(String contributor: tokens){
				/* TODO these are going to be artists, narrators, 
				 * additional authors and possibly editors. I don't
				 * think we can parse this, though we might be able to 
				 * guess based on the Binding and/or a user's shelves.
				 * 
				 * For now everyone gets to be "Unknown". Maybe add in
				 * data enrichment post parsing? 
				 */
				if((contributor != null) && (!"".equals(contributor))){
					contributors.add(getContributor(contributor,
							ContributorRole.UNKNOWN));
				}
			}
		}catch (IOException e) {
			logger.error("Problem parsing additional contributors", e);
		}
	}
	
	return contributors;
}
 
开发者ID:robertzak,项目名称:goodreads-parser,代码行数:35,代码来源:GoodReadsParsingService.java


注:本文中的au.com.bytecode.opencsv.CSVParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。