arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
435 stars 76 forks source link

Csv Writer easier to write Iterable<? extends CharSequence[]> #686

Closed arnaudroger closed 4 years ago

ryanthara commented 4 years ago

I have coordinate based inputs which are stored in List<String[]> and it would be great to use them directly with CsvWriter class.

arnaudroger commented 4 years ago

@ryanthara just pushed new version for a List<String[]> the code would look likethat

try(ClosableCsvWriter writer = CsvWriter.dsl().to(file)) { list.forEach(writter::appendRow); }

the new CsvWriter is in package org.simpleflatmapper.lightningcsv.CsvWriter, not the same as the one in org.simpleflatmapper.csv

ryanthara commented 4 years ago

Excellent work @arnaudroger

Sounds good.

When will it be available via maven?

arnaudroger commented 4 years ago

it's there https://repo1.maven.org/maven2/org/simpleflatmapper/lightning-csv/8.1.0/

On Fri, Nov 1, 2019 at 5:11 AM Sebastian notifications@github.com wrote:

Sounds good.

When will it be available via maven?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/arnaudroger/SimpleFlatMapper/issues/686?email_source=notifications&email_token=ABPAJLMIC6QZGYPMO6AEDUDQRO27HA5CNFSM4JC2MNX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC2AJPI#issuecomment-548668605, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPAJLN3FKB5VFAMD6GNJUTQRO27HANCNFSM4JC2MNXQ .

ryanthara commented 4 years ago

I checked this site here.

Still 8.0.3, but with your link @arnaudroger everything works fine.

arnaudroger commented 4 years ago

That’s a clone of maven central always a bit late.

ryanthara commented 4 years ago

@arnaudroger

Some addition, maybe for other users too.

try(ClosableCsvWriter writer = CsvWriter.dsl().to(file)) { list.forEach(writer::appendRow); }

has to be changed to

try (ClosableCsvWriter writer = CsvWriter.dsl().to(path.toFile())) { csv.forEach(values -> { try { writer.appendRow(values); } catch (IOException e) { // do whatever you want } }); } catch (IOException e) { // do whatever you want }

You have to try catch every element of the forEach-loop.

arnaudroger commented 4 years ago

you can try also

try(ClosableCsvWriter writer = CsvWriter.dsl().to(file)) { 
    list.forEach(CheckedConsumer.toConsumer(writer::appendRow)); 
}

that should work

ryanthara commented 4 years ago

@arnaudroger +1

Works like a charm.