本文整理汇总了Java中com.fasterxml.jackson.dataformat.csv.CsvMapper.writer方法的典型用法代码示例。如果您正苦于以下问题:Java CsvMapper.writer方法的具体用法?Java CsvMapper.writer怎么用?Java CsvMapper.writer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.dataformat.csv.CsvMapper
的用法示例。
在下文中一共展示了CsvMapper.writer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Setup(Level.Iteration)
public void setUp() {
dsl = CsvWriter.from(SmallBenchmarkObject.class).skipHeaders();
sbo = new SmallBenchmarkObject();
sbo.setId(2);
sbo.setEmail("[email protected]");
sbo.setName("name");
sbo.setYearStarted(222);
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(SmallBenchmarkObject.class);
myObjectWriter = mapper.writer(schema);
settings = new CsvWriterSettings();
settings.setHeaders("id", "year_started", "name", "email");
settings.setRowWriterProcessor(new BeanWriterProcessor<SmallBenchmarkObject>(SmallBenchmarkObject.class));
}
示例2: createObjectWriter
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
/**
* Creates a Jackson object writer based on a mapper. Has a special handling
* for CSV media types.
*
* @return The Jackson object writer.
*/
protected ObjectWriter createObjectWriter() {
ObjectWriter result = null;
if (MediaType.TEXT_CSV.isCompatible(getMediaType())) {
CsvMapper csvMapper = (CsvMapper) getObjectMapper();
CsvSchema csvSchema = createCsvSchema(csvMapper);
result = csvMapper.writer(csvSchema);
} else {
result = getObjectMapper().writerFor(getObjectClass());
}
return result;
}
示例3: generateCsvReport
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public void generateCsvReport(List<ZeroCodeCsvReport> zeroCodeCsvReportRows) {
/*
* Write to a CSV file
*/
CsvSchema schema = CsvSchema.builder()
.setUseHeader(true)
.addColumn("scenarioName")
.addColumn("scenarioLoop", CsvSchema.ColumnType.NUMBER)
.addColumn("stepName")
.addColumn("stepLoop", CsvSchema.ColumnType.NUMBER)
.addColumn("correlationId")
.addColumn("requestTimeStamp")
.addColumn("responseTimeStamp")
.addColumn("responseDelayMilliSec", CsvSchema.ColumnType.NUMBER)
.addColumn("result")
.build();
CsvMapper csvMapper = new CsvMapper();
csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
ObjectWriter writer = csvMapper.writer(schema.withLineSeparator("\n"));
try {
writer.writeValue(
new File(TARGET_FULL_REPORT_DIR +
TARGET_FULL_REPORT_CSV_FILE_NAME +
"_" +
LocalDateTime.now().toString().replace(":", "-") +
".csv"),
zeroCodeCsvReportRows);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Exception while Writing full CSV report. Details: " + e);
}
}
示例4: main
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public static void main(String[] args) {
List<User> users = new ArrayList<>();
User userHeader = new User("First", "Last", "Age");
User user1 = new User("First name1", "Last Name1", null);
User user2 = new User("First name2", "Last Name2", "22");
users.add(userHeader);
users.add(user1);
users.add(user2);
CsvSchema schema = CsvSchema.builder()
.addColumn("firstName")
.addColumn("lastName")
.addColumn("age", CsvSchema.ColumnType.NUMBER)
//.addColumn("comments")
//.setUseHeader(true)
//.setStrictHeaders(false)
.build();
// CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
// ObjectMapper mapper = new CsvMapper();
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
ObjectWriter writer = mapper.writer(schema.withLineSeparator("\n"));
try {
writer.writeValue(new File("target/ModifiedUsers.csv"), users);
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: buildWriter
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
private ObjectWriter buildWriter(boolean includeWeight) {
CsvMapper csvMapper = new CsvMapper();
Class<? extends JsonBiasModellingDiseaseOccurrence> type =
includeWeight ? JsonModellingDiseaseOccurrence.class : JsonBiasModellingDiseaseOccurrence.class;
return csvMapper.writer(csvMapper.schemaFor(type).withHeader());
}
示例6: writeCsvResult
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
private static void writeCsvResult(final FileIoStats stats) {
if (params.getResultCsvFile() == null) {
return;
}
final Object[] results = new Object[] {
new Date().toGMTString(),
params.getNumFiles(),
params.getNumThreads(),
params.getReplication(),
params.getBlockSize(),
params.getIoSize(),
stats.getFilesWritten(),
stats.getBytesWritten(),
stats.getMeanCreateTimeMs(),
stats.getMeanWriteTimeMs(),
stats.getMeanCloseTimeMs(),
stats.getElapsedTimeMs(),
(params.getFileSize() * 1000) / stats.getElapsedTimeMs(),
(params.getNumFiles() * params.getFileSize() * 1000) /
stats.getElapsedTimeMs(),
params.getNote()
};
final CsvSchema schema = CsvSchema.builder()
.setColumnSeparator(';')
.setQuoteChar('"')
.setUseHeader(!params.getResultCsvFile().exists())
.addColumn("timestamp", CsvSchema.ColumnType.STRING)
.addColumn("number of files", CsvSchema.ColumnType.NUMBER)
.addColumn("number of threads", CsvSchema.ColumnType.NUMBER)
.addColumn("replication factor", CsvSchema.ColumnType.NUMBER)
.addColumn("block size", CsvSchema.ColumnType.NUMBER)
.addColumn("io size", CsvSchema.ColumnType.NUMBER)
.addColumn("total files written", CsvSchema.ColumnType.NUMBER)
.addColumn("total bytes written", CsvSchema.ColumnType.NUMBER)
.addColumn("mean time to create file in ms", CsvSchema.ColumnType.NUMBER)
.addColumn("mean time to write file in ms", CsvSchema.ColumnType.NUMBER)
.addColumn("mean time to close file in ms", CsvSchema.ColumnType.NUMBER)
.addColumn("total ms", CsvSchema.ColumnType.NUMBER)
.addColumn("mean throughput bytes per s", CsvSchema.ColumnType.NUMBER)
.addColumn("aggregate throughput bytes per s", CsvSchema.ColumnType.NUMBER)
.addColumn("note", CsvSchema.ColumnType.STRING)
.build();
try (FileWriter fileWriter = new FileWriter(params.getResultCsvFile(), true)) {
final CsvMapper mapper = new CsvMapper();
final ObjectWriter writer = mapper.writer(schema);
writer.writeValue(fileWriter, results);
} catch (IOException e) {
LOG.error("Could not write results to CSV file '{}': '{}'",
params.getResultCsvFile().getPath(), e.getMessage());
}
}