use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper in project snow-owl by b2ihealthcare.
the class ConceptMapCompareDsvExportRequest method execute.
@Override
public File execute(ServiceProvider context) {
final List<ConceptMapCompareResultItem> resultsToExport = items.stream().filter(item -> changeKinds.contains(item.getChangeKind())).collect(Collectors.toList());
final CsvMapper mapper = new CsvMapper();
final CsvSchema schema = mapper.schemaFor(ConceptMapCompareResultItem.class).withHeader().withoutQuoteChar().withColumnSeparator(delimiter).withNullValue("");
try (OutputStream newOutputStream = Files.newOutputStream(Paths.get(filePath), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
mapper.writer(schema).writeValue(newOutputStream, resultsToExport);
} catch (Exception e) {
throw new BadRequestException("An error occured durin Concept Map Compare DSV export: %s", Throwables.getRootCause(e).getMessage());
}
return Paths.get(filePath).toFile();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper in project registry by hortonworks.
the class TruckEventsCsvConverter method readTruckEventsFromCsv.
private MappingIterator<TruckEvent> readTruckEventsFromCsv(InputStream csvStream) throws IOException {
CsvSchema bootstrap = CsvSchema.builder().addColumn("driverId", CsvSchema.ColumnType.NUMBER).addColumn("truckId", CsvSchema.ColumnType.NUMBER).addColumn("eventTime", CsvSchema.ColumnType.STRING).addColumn("eventType", CsvSchema.ColumnType.STRING).addColumn("longitude", CsvSchema.ColumnType.NUMBER).addColumn("latitude", CsvSchema.ColumnType.NUMBER).addColumn("eventKey", CsvSchema.ColumnType.STRING).addColumn("correlationId", CsvSchema.ColumnType.NUMBER).addColumn("driverName", CsvSchema.ColumnType.STRING).addColumn("routeId", CsvSchema.ColumnType.NUMBER).addColumn("routeName", CsvSchema.ColumnType.STRING).addColumn("eventDate", CsvSchema.ColumnType.STRING).build().withHeader();
CsvMapper csvMapper = new CsvMapper();
return csvMapper.readerFor(TruckEvent.class).with(bootstrap).readValues(csvStream);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper in project mapping-benchmark by arnaudroger.
the class JacksonCsvParserBenchmark method main.
public static void main(String[] args) throws IOException {
CsvParam csvParam = new CsvParam();
csvParam.setUp();
CsvMapper csvMapper = new CsvMapper();
csvMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
try (Reader reader = csvParam.getReader()) {
MappingIterator<City> iterator = csvMapper.readerFor(City.class).with(bootstrapSchema).readValues(reader);
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper in project mapping-benchmark by arnaudroger.
the class JacksonCsvParserBenchmark method setUp.
@Setup
public void setUp() {
csvMapperToStringArray = new CsvMapper();
csvMapperToStringArray.enable(com.fasterxml.jackson.dataformat.csv.CsvParser.Feature.WRAP_AS_ARRAY);
CsvMapper csvMapperToCity = new CsvMapper();
csvMapperToCity.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
cityReader = csvMapperToCity.readerFor(City.class).with(bootstrapSchema);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper in project snow-owl by b2ihealthcare.
the class CsvMessageConverter method writeInternal.
@Override
protected void writeInternal(Collection<Object> items, HttpOutputMessage output) throws IOException, HttpMessageNotWritableException {
if (!items.isEmpty()) {
output.getHeaders().setContentType(MEDIA_TYPE);
output.getHeaders().set(CONTENT_DISPOSITION, ATTACHMENT);
try (OutputStream out = output.getBody()) {
final CsvMapper mapper = new CsvMapper();
mapper.readerFor(Collection.class);
// XXX The mapper is auto closing the writer after the first write out for some reason
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
final CsvSchema schema = mapper.schemaFor(items.iterator().next().getClass()).withHeader().withColumnSeparator('\t');
final ObjectWriter writer = mapper.writer(schema);
writer.writeValues(out).writeAll(items);
}
}
}
Aggregations