本文整理汇总了Java中org.apache.commons.csv.CSVPrinter.print方法的典型用法代码示例。如果您正苦于以下问题:Java CSVPrinter.print方法的具体用法?Java CSVPrinter.print怎么用?Java CSVPrinter.print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.csv.CSVPrinter
的用法示例。
在下文中一共展示了CSVPrinter.print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toCSVLine
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
@Override
public void toCSVLine(CSVPrinter rec, Object obj) throws IOException {
if(this.taxent == null) {
rec.print("");
return;
}
Map<String,InferredStatus> tStatus = this.inferNativeStatus();
@SuppressWarnings("unchecked")
List<String> allTerritories=(List<String>) obj;
rec.print(this.taxent.getCurrent() ? "yes" : "no");
rec.print(this.taxent.getID());
rec.print((this.isLeaf ==null ? "" : (this.isLeaf ? "" : "+")) + this.taxent.getNameWithAnnotationOnly(false));
rec.print(this.taxent.getAuthor());
if(this.territories==null) return;
for(String t : allTerritories) {
if(tStatus.containsKey(t))
rec.print(tStatus.get(t).getStatusSummary());
else
rec.print("");
}
rec.print(this.taxent.getComment());
}
示例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: toCSVLine
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
@Override
public void toCSVLine(CSVPrinter rec, Object obj) throws IOException {
TaxonomicPath taxonomicPath;
taxonomicPath = new TaxonomicPath(this.higherTaxonomy);
if (this.taxent == null) {
rec.print("");
return;
}
// rec.print(taxonomicPath.toString());
TaxEnt tmp;
for(Constants.TaxonRanks cf : Constants.CHECKLISTFIELDS) {
if((tmp = taxonomicPath.getTaxonOfRank(cf)) == null)
rec.print("");
else
rec.print(tmp.getFullName(false));
}
super.toCSVLine(rec, obj);
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: writeObjectHeader
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private void writeObjectHeader(CSVPrinter outputStream) throws IOException {
Field last = classFields.remove(classFields.size() - 1);
for (Field field : classFields) {
outputStream.print(getFieldName(field));
}
outputStream.print(getFieldName(last));
outputStream.print('\n');
}
示例7: 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();
}
示例8: tableToCsv
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
/**
* Converts Guava table to a CSV table
*
* @param table table
* @param csvFormat CSV format
* @param missingValuePlaceholder print if a value is missing (empty string by default)
* @param <T> object type (string)
* @return table
* @throws IOException exception
*/
public static <T> String tableToCsv(Table<String, String, T> table, CSVFormat csvFormat,
String missingValuePlaceholder)
throws IOException
{
StringWriter sw = new StringWriter();
CSVPrinter printer = new CSVPrinter(sw, csvFormat);
List<String> firstRow = new ArrayList<>();
firstRow.add(" ");
firstRow.addAll(table.columnKeySet());
printer.printRecord(firstRow);
for (String rowKey : table.rowKeySet()) {
printer.print(rowKey);
for (String columnKey : table.columnKeySet()) {
T value = table.get(rowKey, columnKey);
if (value == null) {
printer.print(missingValuePlaceholder);
}
else {
printer.print(value);
}
}
printer.println();
}
printer.close();
return sw.toString();
}
示例9: convertTestCase
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
private void convertTestCase(TestCase testCase, CSVPrinter printer) throws IOException {
Boolean clearOnExit = testCase.getTestSteps().isEmpty();
testCase.loadTableModel();
for (TestStep testStep : testCase.getTestSteps()) {
if (testStep.isReusableStep()) {
TestCase rTestCase = testCase.getProject()
.getScenarioByName(testStep.getReusableData()[0])
.getTestCaseByName(testStep.getReusableData()[1]);
convertTestCase(rTestCase, printer);
} else if (!testStep.getAction().isEmpty()) {
printer.print(testCase.getScenario().getName());
printer.print(testCase.getName());
printer.print(testStep.getAction());
CSVRecord descRecord = getRecordByAction(testStep.getAction());
if (descRecord != null) {
printer.print(resolve(testStep, descRecord.get("Description")));
printer.print(resolve(testStep, descRecord.get("Expected Result")));
} else {
printer.print(resolve(testStep, MethodInfoManager.getDescriptionFor(testStep.getAction())));
printer.print("");
}
printer.println();
}
}
if (clearOnExit) {
testCase.getTestSteps().clear();
}
}
示例10: printReport
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
void printReport(CSVPrinter csvPrinter, Set<SchemaEntity> schemaEntities) throws IOException {
for (SchemaEntity entity : schemaEntities) {
switch (entity.getSchemaEntityType()) {
case NAMESPACE:
namespaceReportString = entity.getNameAsString();
tableReportString = "";
colFamilyReportString = "";
colQualifierReportString = "";
colMaxLengthReportString = "";
printReport(csvPrinter, entity.getChildren());
break;
case TABLE:
tableReportString = entity.getNameAsString();
printReport(csvPrinter, entity.getChildren());
break;
case COLUMN_FAMILY:
colFamilyReportString = entity.getNameAsString();
if (this.sourceColFamily != null
&& !colFamilyReportString.equals(Bytes.toString(sourceColFamily))) {
continue;
}
printReport(csvPrinter, entity.getChildren());
break;
case COLUMN_AUDITOR:
colQualifierReportString = entity.getNameAsString();
colMaxLengthReportString = entity.getValue(ColumnAuditor.MAX_VALUE_LENGTH_KEY);
csvPrinter.print(namespaceReportString);
csvPrinter.print(tableReportString);
csvPrinter.print(colFamilyReportString);
csvPrinter.print(colQualifierReportString);
csvPrinter.print(colMaxLengthReportString);
csvPrinter.println();
recordsWrittenToReport = true;
}
}
}
示例11: dumpFeatures
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
public void dumpFeatures(List<FullyResolvedEntry> entries, FileProvider.FeatureSet output) throws IOException {
FileWriter svmOutput = new FileWriter(output.SVMFeat);
CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(output.CSVFeat), CSVFormat.DEFAULT);
CSVPrinter indexPrinter = new CSVPrinter(new FileWriter(output.index), CSVFormat.DEFAULT);
for (FullyResolvedEntry entry : entries) {
int order = 0;
for (User user : entry.candidates) {
indexPrinter.printRecord(entry.resource.getIdentifier(), user.getId(), user.getScreenName());
boolean isPositive = user.getScreenName().equals(entry.entry.twitterId);
double[] features = entry.features.get(order);
csvPrinter.print(isPositive ? 1 : 0);
svmOutput.write(String.valueOf(isPositive ? 1 : 0));
for (int i = 0; i < features.length; i++) {
csvPrinter.print(features[i]);
svmOutput.write(" " + (i + 1) + ":");
svmOutput.write(String.valueOf(features[i]));
}
svmOutput.write('\n');
csvPrinter.println();
order++;
}
}
IOUtils.closeQuietly(svmOutput);
indexPrinter.close();
csvPrinter.close();
}
示例12: writeToStreamAndClose
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
/**
* Helper that writes the given lines (adding a newline in between) to a stream, then closes the
* stream.
*/
private static void writeToStreamAndClose(List<Object[]> rows, OutputStream outputStream) {
try (PrintStream writer = new PrintStream(outputStream)) {
CSVPrinter printer = CSVFormat.DEFAULT.print(writer);
for (Object[] row : rows) {
for (Object field : row) {
printer.print(field);
}
printer.println();
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: getCSVHeader
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
@Override
public void getCSVHeader(CSVPrinter rec, Object obj) throws IOException {
@SuppressWarnings("unchecked")
List<String> territories=(List<String>) obj;
rec.print("accepted");
rec.print("id");
rec.print("canonicalName");
rec.print("authority");
for(String t : territories) {
rec.print(t);
}
rec.print("comment");
rec.println();
}
示例14: toCSVLine
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
@Override
public void toCSVLine(CSVPrinter rec, Object obj) throws IOException {
// TODO obsolete!
rec.print(this.count);
rec.print(this.taxent.getID());
rec.print(Arrays.toString(this.reltypes));
rec.print((this.isLeaf ==null ? "" : (this.isLeaf ? "" : "+"))+(this.taxent.getCurrent() ? "" : "-")+this.taxent.getNameWithAnnotationOnly(false)+(this.partim ? " (partim)" : ""));
rec.print(Arrays.toString(this.match)); // FIXME handle the array!
}
示例15: getCSVHeader
import org.apache.commons.csv.CSVPrinter; //导入方法依赖的package包/类
@Override
public void getCSVHeader(CSVPrinter rec, Object obj) throws IOException {
// rec.print("higherTaxonomy");
for(Constants.TaxonRanks cf : Constants.CHECKLISTFIELDS)
rec.print(cf.getName().toLowerCase());
super.getCSVHeader(rec, obj);
}