本文整理汇总了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();
}
示例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);
}
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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++;
}
}
示例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();
}
}
示例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();
}
示例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);
}
}
}
}
示例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);
}
}
}
}