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


Java CSVPrinter.printRecord方法代码示例

本文整理汇总了Java中org.apache.commons.csv.CSVPrinter.printRecord方法的典型用法代码示例。如果您正苦于以下问题:Java CSVPrinter.printRecord方法的具体用法?Java CSVPrinter.printRecord怎么用?Java CSVPrinter.printRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.csv.CSVPrinter的用法示例。


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

示例1: exportMetaDataToCSV

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
public static String exportMetaDataToCSV(List<StandaloneArgument> arguments)
        throws IOException
{
    StringWriter sw = new StringWriter();
    CSVPrinter csvPrinter = new CSVPrinter(sw, CSVFormat.DEFAULT.withHeader(
            "id", "author", "annotatedStance", "timestamp", "debateMetaData.title",
            "debateMetaData.description", "debateMetaData.url"
    ));

    for (StandaloneArgument argument : arguments) {
        csvPrinter.printRecord(
                argument.getId(),
                argument.getAuthor(),
                argument.getAnnotatedStance(),
                argument.getTimestamp(),
                argument.getDebateMetaData().getTitle(),
                argument.getDebateMetaData().getDescription(),
                argument.getDebateMetaData().getUrl()
        );
    }

    sw.flush();

    return sw.toString();
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:26,代码来源:ExportHelper.java

示例2: logResults

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private void logResults() {
	logger.info("Action frequency distribution:\n" + FrequencyUtils.formatFrequency(actionDistribution));
	logger.info("Action frequency distribution of rollback-reverted revisions:\n" + FrequencyUtils.formatFrequency(rollbackRevertedActionDistribution));
	logger.info("Action frequency distribution of non-rollback-reverted revisions:\n" + FrequencyUtils.formatFrequency(nonRollbackRevertedActionDistribution));
	
	try {
		Writer writer = new PrintWriter(path, "UTF-8");
		CSVPrinter csvWriter = CSVFormat.RFC4180.withQuoteMode(QuoteMode.ALL)
				.withHeader("month", "action", "count").print(writer);
		
		for (Entry<String, HashMap<String, Integer>> entry: getSortedList(monthlyActionDistribution)) {
			String month = entry.getKey();
			
			for (Entry<String, Integer> entry2: getSortedList2(entry.getValue())) {
				String action = entry2.getKey();
				Integer value = entry2.getValue();

				csvWriter.printRecord(month, action, value);
			}
		}
		csvWriter.close();
	} catch (IOException e) {
		logger.error("", e);
	}
}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:26,代码来源:ActionStatisticsProcessor.java

示例3: writeVertexCSV

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
/**
 * Create csv files for a VertexType
 * @param type a vertex type
 * @param outputDirectory the output folder to write the csv file
 */
void writeVertexCSV(VertexTypeBean type, String outputDirectory ){
    String csvFile = outputDirectory + "/" + type.name + ".csv";
    ArrayList<String> header = new ArrayList<String>();
    header.add("node_id");
    header.addAll(type.columns.keySet());
    int botId = idFactory.getMinId(type.name);
    int topId = idFactory.getMaxId(type.name);
    try {
        CSVPrinter csvFilePrinter = new CSVPrinter(new FileWriter(csvFile), csvFileFormat);
        csvFilePrinter.printRecord(header);
        for (int i = botId; i<=topId; i++){
            ArrayList<Object> record = new ArrayList<Object>();
            record.add(i);
            record.addAll(generateOneRecord(type.columns));
            csvFilePrinter.printRecord(record);
        }
        csvFilePrinter.close();
        System.out.println("Generated vertex file: "+ csvFile);
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}
 
开发者ID:IBM,项目名称:janusgraph-utils,代码行数:28,代码来源:CSVGenerator.java

示例4: writeVertexCSV

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
void writeVertexCSV(VertexTypeBean type, String outputDirectory ){
    String csvFile = outputDirectory + "/" + type.name + ".csv";
    ArrayList<String> header = new ArrayList<String>();
    header.add("node_id");
    header.addAll(type.columns.keySet());
    int botId = idFactory.getMinId(type.name);
    int topId = idFactory.getMaxId(type.name);
    try {
        CSVPrinter csvFilePrinter = new CSVPrinter(new FileWriter(csvFile), csvFileFormat);
        csvFilePrinter.printRecord(header);
        for (int i = botId; i<=topId; i++){
            ArrayList<Object> record = new ArrayList<Object>();
            record.add(i);
            record.addAll(generateOneRecord(type.columns));
            csvFilePrinter.printRecord(record);
        }
        csvFilePrinter.close();
        System.out.println("Generated vertex file: "+ csvFile);
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}
 
开发者ID:tedhtchang,项目名称:JanusGraphBench,代码行数:23,代码来源:CSVGenerator.java

示例5: processRecordY

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
public static List processRecordY(CSVPrinter printer, GenericRecord record, List<Column> columns)
		throws IOException {
	List r = new ArrayList<>();
	columns.forEach(c -> {
		try {
			r.add(record.get(c.getField().name()));
		} catch (Exception e) {

			try {
				r.add(c.getDefaultValue());
			} catch (Exception e2) {
				r.add("NULL");
			}
		}
	});

	printer.printRecord(r);
	printer.flush();
	return r;
}
 
开发者ID:cslbehring,项目名称:public_hdf_processors_ConvertAvroToCSV,代码行数:21,代码来源:CsvProcessor.java

示例6: appendCSV

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
/**
 * this method is used to append pending transactions to the csv file
 * @param trans
 */
public void appendCSV(UserStockTransaction trans){
	try{
		
		filePath = servletContext.getRealPath("WEB-INF/csv/pending.csv");
		File f = new File(filePath);
		//System.out.println(trans.getStock().getSymbol() + " " + trans.getUser().getUsername() + " " + trans.getPrice());
		
		FileWriter fw = new FileWriter(f, true);			
		CSVPrinter cp = new CSVPrinter(fw, CSVFormat.DEFAULT);
		System.out.println("Appending a transaction");
		System.out.println(trans.toString());
		cp.printRecord((Object[]) trans.toString().split(","));
		fw.flush();
		fw.close();
		cp.close();
	}catch (Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:yyang325,项目名称:YahooFinanceTradingSystem,代码行数:24,代码来源:CsvUtil.java

示例7: rewriteCSV

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
/**
 * this method is used to rewrite the csv file for all the pending transactions
 * @param trans
 */
public void rewriteCSV(List<UserStockTransaction> trans){
	try{
		
		filePath = servletContext.getRealPath("WEB-INF/csv/pending.csv");
		File f = new File(filePath);
		
		FileWriter fw = new FileWriter(f);			
		CSVPrinter cp = new CSVPrinter(fw, CSVFormat.DEFAULT);
		System.out.println(trans.toString());
		for(UserStockTransaction tx: trans){
			cp.printRecord((Object[]) tx.toString().split(","));
		}
		fw.flush();
		fw.close();
		cp.close();			
	}catch (Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:yyang325,项目名称:YahooFinanceTradingSystem,代码行数:24,代码来源:CsvUtil.java

示例8: printRecord

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private void printRecord(CSVPrinter csv, String version, String fileName, CSVRecord record) throws IOException {
    List<Object> values = new ArrayList<>();

    values.add(version);
    values.add(fileName);
    for (Measure measure : Measure.values()) {
        values.add(record.get(measure.columnMin()));
        values.add(record.get(measure.columnMax()));
        values.add(record.get(measure.columnMean()));
        values.add(record.get(measure.columnStandardDeviation()));
        values.add(record.get(measure.columnMedian()));
        values.add(record.get(measure.column75Percentile()));
    }

    csv.printRecord(values);
}
 
开发者ID:wildfly-swarm,项目名称:process-monitor,代码行数:17,代码来源:CsvOutputComparator.java

示例9: produceCsvMessages

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
public List<KeyedMessage<String, String>> produceCsvMessages(String topic, String partition,
                                                                    CSVFormat csvFormat, File csvFile) throws IOException {
  List<KeyedMessage<String, String>> messages = new ArrayList<>();
  String line;
  BufferedReader bufferedReader = new BufferedReader(new FileReader(KafkaTestUtil.class.getClassLoader()
    .getResource("testKafkaTarget.csv").getFile()));
  while ((line = bufferedReader.readLine()) != null) {
    String[] strings = line.split(",");
    StringWriter stringWriter = new StringWriter();
    CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
    csvPrinter.printRecord(strings);
    csvPrinter.flush();
    csvPrinter.close();
    messages.add(new KeyedMessage<>(topic, partition, stringWriter.toString()));
  }
  return messages;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:18,代码来源:SdcKafkaTestUtil.java

示例10: produceCsvMessages

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
public static List<KeyedMessage<String, String>> produceCsvMessages(String topic, String partition,
                                                                    CSVFormat csvFormat, File csvFile) throws IOException {
  List<KeyedMessage<String, String>> messages = new ArrayList<>();
  String line;
  BufferedReader bufferedReader = new BufferedReader(new FileReader(KafkaTestUtil.class.getClassLoader()
    .getResource("testKafkaTarget.csv").getFile()));
  while ((line = bufferedReader.readLine()) != null) {
    String[] strings = line.split(",");
    StringWriter stringWriter = new StringWriter();
    CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
    csvPrinter.printRecord(strings);
    csvPrinter.flush();
    csvPrinter.close();
    messages.add(new KeyedMessage<>(topic, partition, stringWriter.toString()));
  }
  return messages;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:18,代码来源:KafkaTestUtil.java

示例11: configurationSetsWithItemsToCsv

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private static void configurationSetsWithItemsToCsv(CSVPrinter aOut,
        AgreementResult aAgreement, List<ConfigurationSet> aSets)
    throws IOException
{
    List<String> headers = new ArrayList<>(
            asList("Type", "Collection", "Document", "Layer", "Feature", "Position"));
    headers.addAll(aAgreement.getCasGroupIds());
    aOut.printRecord(headers);
    
    int i = 0;
    for (ICodingAnnotationItem item : aAgreement.getStudy().getItems()) {
        Position pos = aSets.get(i).getPosition();
        List<String> values = new ArrayList<>();
        values.add(pos.getClass().getSimpleName());
        values.add(pos.getCollectionId());
        values.add(pos.getDocumentId());
        values.add(pos.getType());
        values.add(aAgreement.getFeature());
        values.add(aSets.get(i).getPosition().toMinimalString());
        for (IAnnotationUnit unit : item.getUnits()) {
            values.add(String.valueOf(unit.getCategory()));
        }
        aOut.printRecord(values);
        i++;
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:27,代码来源:AgreementUtils.java

示例12: writeExtractedDefinitionsAsCsv

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
public static void writeExtractedDefinitionsAsCsv(String file, String qId, String title, List<Relation> relations) throws IOException {
  if (file != null) {
    final File output = new File(file);
    if (!output.exists())
      output.createNewFile();
    OutputStreamWriter w = new FileWriter(output, true);
    CSVPrinter printer = CSVFormat.DEFAULT.withRecordSeparator("\n").print(w);
    for (Relation relation : relations) {
      //qId, title, identifier, definition
      String[] out = new String[]{
        qId,
        title,
        relation.getIdentifier(),
        relation.getDefinition(), "Word number: " + String.valueOf(relation.getIdentifierPosition()),
        "\"" + "\"",
        getHumanReadableSentence(relation)};
      printer.printRecord(out);
    }
    w.flush();
    w.close();
  }
}
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:23,代码来源:Util.java

示例13: writeOrderedMatrix

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private static void writeOrderedMatrix(HashMap<Tuple2<String, String>, Double> matrix, String filepath, List<String> orderedRowValues, List<String> orderedColValues) throws Exception {
    // print to disk
    final CSVPrinter printer = new CSVPrinter(new FileWriter(filepath), CSV_FORMAT);

    // write first row (header)
    List<String> tmpHeader = new ArrayList<>();
    tmpHeader.add("");
    tmpHeader.addAll(orderedColValues);
    printer.printRecord(tmpHeader);

    System.out.println("writing " + orderedRowValues.size() + " records");
    for (String rowName : orderedRowValues) {
        printer.printRecord(
                getRowWithDescriptionInFirstCol(
                        rowName,
                        getOrderedRow(matrix, orderedColValues, rowName)));
    }
    printer.close();
}
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:20,代码来源:ConverterPairCSVToMatrix.java

示例14: fileExportAllMenuActionPerformed

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private void fileExportAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileExportAllMenuActionPerformed
    if (occurrences != null && occurrences.size() > 0) {
        if (saveFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            File file = saveFileChooser.getSelectedFile();
            try {
                Appendable out = new FileWriter(file);
                CSVPrinter printer = CSVFormat.EXCEL.withHeader("year", "word", "score").withDelimiter('\t').print(out);
                List<Integer> years = new ArrayList<>(occurrences.keySet());
                Collections.sort(years);
                for (Integer year : years) {
                    List<Word> list = occurrences.get(year);
                    for (Word word : list) {
                        printer.printRecord(year, word.getWord(), word.getScore());
                    }
                }
                printer.close();
            } catch (IOException ex) {
                Logger.getLogger(OccSearchGUI.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, ex.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}
 
开发者ID:pippokill,项目名称:tri,代码行数:24,代码来源:OccSearchGUI.java

示例15: fileExportMenuActionPerformed

import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private void fileExportMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileExportMenuActionPerformed
    Object selectedItem = comboYearResult.getSelectedItem();
    if (selectedItem != null) {
        if (saveFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            File file = saveFileChooser.getSelectedFile();
            try {
                Appendable out = new FileWriter(file);
                CSVPrinter printer = CSVFormat.EXCEL.withHeader("year", "word", "score").withDelimiter('\t').print(out);
                List<Word> list = occurrences.get((Integer) selectedItem);
                for (Word word : list) {
                    printer.printRecord((Integer) selectedItem, word.getWord(), word.getScore());
                }
                printer.close();
            } catch (IOException ex) {
                Logger.getLogger(OccSearchGUI.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, ex.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}
 
开发者ID:pippokill,项目名称:tri,代码行数:21,代码来源:OccSearchGUI.java


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