本文整理匯總了Java中org.apache.commons.csv.CSVPrinter.close方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVPrinter.close方法的具體用法?Java CSVPrinter.close怎麽用?Java CSVPrinter.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.csv.CSVPrinter
的用法示例。
在下文中一共展示了CSVPrinter.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: 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());
}
}
示例3: 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());
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: writeTo
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public void writeTo(OutputStream outputStream) throws IOException {
try (OutputStreamWriter osw = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
CSVPrinter csvPrinter = new CSVPrinter(osw, CSVFormat.DEFAULT);
for (Object doc : docs) {
if (doc instanceof Map) {
Map<String,Object> map = (Map<String,Object>)doc;
csvPrinter.printRecord(map.values());
} else {
csvPrinter.print(doc);
csvPrinter.println();
}
}
csvPrinter.flush();
csvPrinter.close();
}
}
示例7: saveActivities
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
private void saveActivities(Repository repo) throws IOException {
final Appendable out = new FileWriter(getActivitiesFilename());
final CSVPrinter printer = CSVFormat.EXCEL.withHeader("id", "date", "time", "title", "type", "level", "synced").print(out);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
for (Activity game : repo.getActivities()) {
List<String> rec = new ArrayList<>();
rec.add(game.id);
rec.add(formatter.format(game.date));
rec.add(game.time);
rec.add(game.title);
rec.add(game.type.toString());
if (game.level != null)
rec.add(game.level.toString());
else
rec.add("");
rec.add(Boolean.toString(game.synced));
printer.printRecord(rec);
}
printer.close();
}
示例8: 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;
}
示例9: 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;
}
示例10: 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();
}
示例11: 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);
}
}
}
}
示例12: 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);
}
}
}
}
示例13: addFunctions
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public static void addFunctions(List<Function> functions, String allFunctionsFilePath) throws IOException {
File file = new File(allFunctionsFilePath);
boolean exists = false;
if(file.exists()){
exists = true;
}
BufferedWriter bw = new BufferedWriter(new FileWriter(allFunctionsFilePath, true));
CSVPrinter functionPrinter = new CSVPrinter(bw, CSVFormat.DEFAULT.toBuilder().withRecordSeparator("\n").build());
if(!exists) {
printHeader(functionPrinter);
}
for(Function function : functions) {
printFunction(functionPrinter, function);
}
functionPrinter.close();
bw.close();
}
示例14: saveAllFunctions
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
private static void saveAllFunctions(List<Function> functions,
String allFunctionsFilePath) throws IOException {
// rewrite the all.functions file
BufferedWriter bw = new BufferedWriter(new FileWriter(allFunctionsFilePath));
CSVPrinter functionPrinter = new CSVPrinter(bw, CSVFormat.DEFAULT.toBuilder().withRecordSeparator("\n").build());
// print the header
printHeader(functionPrinter);
for(Function function : functions) {
printFunction(functionPrinter, function);
}
functionPrinter.close();
bw.close();
}
示例15: toCSV
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
private StringBuffer toCSV(VOSubscriptionUsageEntry entry) throws IOException {
CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator(System.lineSeparator());
StringBuffer appendable = new StringBuffer();
CSVPrinter csvFilePrinter = new CSVPrinter(appendable, csvFileFormat);
List<String> columns = toList(entry);
csvFilePrinter.printRecord(columns);
csvFilePrinter.close();
return appendable;
}