本文整理匯總了Java中org.apache.commons.csv.CSVPrinter.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVPrinter.flush方法的具體用法?Java CSVPrinter.flush怎麽用?Java CSVPrinter.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.csv.CSVPrinter
的用法示例。
在下文中一共展示了CSVPrinter.flush方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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();
}
}
示例3: 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;
}
示例4: 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;
}
示例5: writeReport
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public void writeReport(Iterable<V> entries, Predicate<V> predicate,
String fileName, CSVFormat format) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
CSVPrinter printer = new CSVPrinter(writer, format);
if (this.useTitles) {
printer.println(this.titles.toArray(new String[titles.size()]));
}
for (V entry : entries) {
if (predicate.apply(entry)) {
List<String> nextLine = new ArrayList<String>();
for (AttributeConverter<V> converter : converters) {
nextLine.add(converter.apply(entry));
}
printer.println(nextLine.toArray(new String[this.converters.size()]));
}
}
printer.flush();
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: print
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public void print(String fileName) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
CSVPrinter printer = new CSVPrinter(writer, CSVFormat.EXCEL);
// print headers
for (int i = 0; i < attributeConverters.size(); i++) {
printer.print(this.attributeNames.get(i));
}
printer.println();
// print rows
for (UnosExchangeUnit unit : this.exchangeUnits) {
if (nodeFilter.apply(unit)) {
for (AttributeConverter<UnosExchangeUnit> converter : this.attributeConverters) {
printer.print(converter.apply(unit));
}
printer.println();
}
}
printer.flush();
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: writeData
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public static void writeData(String path, String fileName, Iterable<Double> values){
String fullFileName = path + fileName + csv;
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(fullFileName));
CSVPrinter printer = new CSVPrinter(writer, CSVFormat.EXCEL);
for(Double value: values){
printer.print(value.toString());
printer.println();
}
printer.flush();
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: print
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
/**
* Prints this dataset to the given output object.
*
* @param out the output object
* @throws IOException if this dataset cannot be printed to the given output object
*/
public void print(final Appendable out) throws IOException {
final String[] header_array = labels.toArray(new String[labels.size()]);
final CSVPrinter printer = new CSVPrinter(out, output_format.withHeader(header_array));
for (final List<String> record : records) {
printer.printRecord(record);
printer.flush();
}
}
示例9: mapToCsv
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
/**
* Map a ResultSet into the provided StringBuffer
* in CSV format
*
* @param rs
* @param additionalFields
* @param ret
* @throws IOException
* @throws SQLException
*/
public void mapToCsv(ResultSet rs, Set<String> additionalFields, StringBuffer ret) throws IOException, SQLException {
final CSVPrinter csvPrinter = new CSVPrinter(ret, csvFormat);
//add titles
for (int i=0;i<openDataFieldsSummary.length;i++) {
csvPrinter.print(openDataFieldsSummary[i]);
}
//add additional Fields
for (String additionalField : additionalFields) {
csvPrinter.print(additionalField);
}
csvPrinter.println();
//add values
while (rs.next())
{
for (int i=0;i<openDataFieldsSummary.length;i++) {
Object val = rs.getObject(openDataFieldsSummary[i]);
csvPrinter.print(val);
}
if (additionalFields != null) {
if (additionalFields.contains("download_classification")) {
csvPrinter.print(Classification.classify(Classification.THRESHOLD_DOWNLOAD,rs.getLong("download_kbit"), 4));
}
if (additionalFields.contains("upload_classification")) {
csvPrinter.print(Classification.classify(Classification.THRESHOLD_UPLOAD,rs.getLong("upload_kbit"), 4));
}
if (additionalFields.contains("ping_classification")) {
csvPrinter.print(Classification.classify(Classification.THRESHOLD_PING,rs.getLong("ping_ms") * 1000000, 4));
}
}
csvPrinter.println();
}
csvPrinter.flush();
}
示例10: writeToCsv
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public static void writeToCsv(OutputStream output, Iterable<? extends List<String>> dumper) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(output, CHARSET);
CSVPrinter printer = new CSVPrinter(writer, CSVFormat.EXCEL
.withDelimiter(';')
.withRecordSeparator('\n')
);
printer.printRecords(dumper);
printer.flush();
printer.close();
writer.close();
}
示例11: run
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public static void run(MlpCommandConfig config) throws Exception {
WikiDocumentOutput output = getWikiDocumentOutput(config);
try (PrintWriter pw = createPrinter(config)) {
List<Relation> relations = output.getRelations();
CSVPrinter printer = CSVFormat.DEFAULT.withRecordSeparator("\n").print(pw);
for (Relation r : relations) {
String[] record = {r.getIdentifier(), r.getDefinition(), Double.toString(r.getScore())};
printer.printRecord(record);
}
printer.flush();
pw.flush();
}
}
示例12: processElement
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
@ProcessElement
public void processElement(ProcessContext c) {
ContentIndexSummary summary = c.element();
if (summary.sentiments == null)
return;
try {
StringWriter stringWriter = new StringWriter();
CSVPrinter csvPrinter = new CSVPrinter(stringWriter,CSVFormat.DEFAULT);
for (int i=0; i < summary.sentiments.length; i++)
{
ArrayList<String> linefields = new ArrayList<String>();
addField(linefields,"RecordID",summary.doc.collectionItemId);
ArrayList<String> sttags = new ArrayList<>();
if (summary.sentiments[i].tags != null)
for (int j=0; j < summary.sentiments[i].tags.length; j++)
sttags.add(summary.sentiments[i].tags[j].tag);
addField(linefields,"Tags",sttags.toString()); // will write as [a,b,c]
addField(linefields,"SentimentHash", summary.sentiments[i].sentimentHash);
addField(linefields,"Text", summary.sentiments[i].text);
addField(linefields,"LabelledPositions", summary.sentiments[i].labelledPositions);
addField(linefields,"AnnotatedText", summary.sentiments[i].annotatedText);
addField(linefields,"AnnotatedHtml", summary.sentiments[i].annotatedHtmlText);
addField(linefields,"SentimentTotalScore", summary.sentiments[i].sentimentTotalScore);
addField(linefields,"DominantValence", summary.sentiments[i].dominantValence.ordinal());
addField(linefields,"StAcceptance", summary.sentiments[i].stAcceptance);
addField(linefields,"StAnger", summary.sentiments[i].stAnger);
addField(linefields,"StAnticipation", summary.sentiments[i].stAnticipation);
addField(linefields,"StAmbiguous", summary.sentiments[i].stAmbiguous);
addField(linefields,"StDisgust", summary.sentiments[i].stDisgust);
addField(linefields,"StFear", summary.sentiments[i].stFear);
addField(linefields,"StGuilt", summary.sentiments[i].stGuilt);
addField(linefields,"StInterest", summary.sentiments[i].stInterest);
addField(linefields,"StJoy", summary.sentiments[i].stJoy);
addField(linefields,"StSadness", summary.sentiments[i].stSadness);
addField(linefields,"StShame", summary.sentiments[i].stShame);
addField(linefields,"StSurprise", summary.sentiments[i].stSurprise);
addField(linefields,"StPositive", summary.sentiments[i].stPositive);
addField(linefields,"StNegative", summary.sentiments[i].stNegative);
addField(linefields,"StSentiment", summary.sentiments[i].stSentiment);
addField(linefields,"StProfane", summary.sentiments[i].stProfane);
addField(linefields,"StUnsafe", summary.sentiments[i].stUnsafe);
ArrayList<String> signalsarray = new ArrayList<>();
if (summary.sentiments[i].signals != null)
for (int j=0; j < summary.sentiments[i].signals.length; j++)
signalsarray.add(summary.sentiments[i].signals[j]);
addField(linefields,"Signals",signalsarray.toString());
csvPrinter.printRecord(linefields);
String output = stringWriter.toString().trim(); // need to trim, because printRecord will add the record separator, as will the TextIO.write method at the end of the pipeline
csvPrinter.flush(); // will also flush the stringWriter
c.output(output);
}
csvPrinter.close();
} catch (IOException e) {
LOG.warn(e.getMessage());
}
}
示例13: writeReport
import org.apache.commons.csv.CSVPrinter; //導入方法依賴的package包/類
public void writeReport(String fileName, CSVFormat format) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
CSVPrinter printer = new CSVPrinter(writer, format);
if (this.outcomesAreRows) {
if (this.showAttributeNames) {
if (showOutcomeNames) {
printer.print("trials");
}
for (int i = 0; i < trialAttributes.size(); i++) {
printer.print(this.trialAttributes.get(i).getAttributeName());
}
printer.println();
}
for (TrialOutcome<V, E, T, D> outcome : this.trialOutcomes) {
if (this.showOutcomeNames) {
printer.print(outcome.getName());
}
for (int i = 0; i < trialAttributes.size(); i++) {
String result = trialAttributes.get(i).apply(outcome);
printer.print(result);
}
printer.println();
}
} else {
if (this.showOutcomeNames) {
if (this.showAttributeNames) {
printer.print("attributes");
}
for (int i = 0; i < this.trialOutcomes.size(); i++) {
printer.print(this.trialOutcomes.get(i).getName());
}
printer.println();
}
for (TrialAttribute<V, E, T, D> attribute : this.trialAttributes) {
if (this.showAttributeNames) {
printer.print(attribute.getAttributeName());
}
for (int i = 0; i < this.trialOutcomes.size(); i++) {
printer.print(attribute.apply(trialOutcomes.get(i)));
}
printer.println();
}
}
printer.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}