Search in sources :

Example 11 with CsvMapper

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();
}
Also used : OutputStream(java.io.OutputStream) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Files(java.nio.file.Files) Request(com.b2international.snowowl.core.events.Request) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) StandardOpenOption(java.nio.file.StandardOpenOption) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) Set(java.util.Set) Throwables(com.google.common.base.Throwables) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Paths(java.nio.file.Paths) ConceptMapCompareChangeKind(com.b2international.snowowl.core.compare.ConceptMapCompareChangeKind) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) ConceptMapCompareResultItem(com.b2international.snowowl.core.compare.ConceptMapCompareResultItem) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) OutputStream(java.io.OutputStream) BadRequestException(com.b2international.commons.exceptions.BadRequestException) ConceptMapCompareResultItem(com.b2international.snowowl.core.compare.ConceptMapCompareResultItem) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 12 with CsvMapper

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);
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper)

Example 13 with CsvMapper

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());
        }
    }
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) Reader(java.io.Reader) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CsvParam(org.simpleflatmapper.param.CsvParam)

Example 14 with CsvMapper

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);
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) Setup(org.openjdk.jmh.annotations.Setup)

Example 15 with CsvMapper

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);
        }
    }
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) OutputStream(java.io.OutputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Aggregations

CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)21 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)15 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)7 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)5 InputStream (java.io.InputStream)5 List (java.util.List)5 CsvMapper (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper)5 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)4 File (java.io.File)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Converter (org.apache.flink.formats.common.Converter)4 CsvSchema (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvSchema)4 FileUploadException (uk.ac.ebi.spot.goci.curation.exception.FileUploadException)4 OutputStream (java.io.OutputStream)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)2 JetException (com.hazelcast.jet.JetException)2 FileOutputStream (java.io.FileOutputStream)2