csv-parser

Simple CSV-Parser

Лицензия

Лицензия

MIT
Категории

Категории

CSV Данные Data Formats
Группа

Группа

com.github.timo-reymann
Идентификатор

Идентификатор

csv-parser
Последняя версия

Последняя версия

4.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

csv-parser
Simple CSV-Parser
Ссылка на сайт

Ссылка на сайт

https://github.com/timo-reymann/csv-parser
Система контроля версий

Система контроля версий

https://github.com/timo-reymann/csv-parser/tree/master

Скачать csv-parser

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.timo-reymann/csv-parser/ -->
<dependency>
    <groupId>com.github.timo-reymann</groupId>
    <artifactId>csv-parser</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.timo-reymann/csv-parser/
implementation 'com.github.timo-reymann:csv-parser:4.0.0'
// https://jarcasting.com/artifacts/com.github.timo-reymann/csv-parser/
implementation ("com.github.timo-reymann:csv-parser:4.0.0")
'com.github.timo-reymann:csv-parser:jar:4.0.0'
<dependency org="com.github.timo-reymann" name="csv-parser" rev="4.0.0">
  <artifact name="csv-parser" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.timo-reymann', module='csv-parser', version='4.0.0')
)
libraryDependencies += "com.github.timo-reymann" % "csv-parser" % "4.0.0"
[com.github.timo-reymann/csv-parser "4.0.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.mapstruct : mapstruct-processor jar 1.3.0.Final

provided (1)

Идентификатор библиотеки Тип Версия
org.projectlombok : lombok jar 1.18.12

test (2)

Идентификатор библиотеки Тип Версия
org.junit.jupiter : junit-jupiter-api jar 5.6.0
org.junit.jupiter : junit-jupiter-engine jar 5.6.0

Модули Проекта

Данный проект не имеет модулей.

CSV-Parser

Maven Central Version Build Status

Parse csv files and other seperated values using java.

Limitations

Currently all primitive types are suppported, plus LocalDate and LocalDateTime.

To use primitive types you must use the boxed types.

How to use?

Add to your depenencies

<dependency>
    <groupId>com.github.timo-reymann</groupId>
    <artifactId>csv-parser</artifactId>
    <version>4.0.0</version>
</dependency>

Create your bean class

Please keep in mind that you need an zero-args constructor for this parser to work properly!

... using the index for mapping

@Data
public class MyBean {
    @CsvColumn(index = 0)
    private Integer id;

    @CsvColumn(index = 1)
    private String firstName;

    @CsvColumn(index = 2)
    private String lastName;

    @CsvColumn(index = 3)
    private String email;

    @CsvColumn(index = 4)
    private String gender;

    @CsvColumn(index = 5)
    private String ip;
}

... using the heading for mapping

@Data
class MyBean {
    @CsvColumn(headerName="id")
    private Integer id;

    @CsvColumn(headerName="first_name")
    private String firstName;

    @CsvColumn(headerName="last_name")
    private String lastName;

    @CsvColumn(headerName="email")
    private String email;

    @CsvColumn(headerName="gender")
    private String gender;

    @CsvColumn(headerName="ip_address")
    private String ip;
}

Write csv file

CsvWriter<MyBean> writer = new CsvWriter.Builder<MyBean>()
             .forClass(MyBean.class)            // entity class
             .file(new File("customers.csv"))   // file
             .outputStream(myInputStream)        // or even stream, but ATTENTION: an OutputStream will always be overwritten
             .noAppend()                        // replace file every time
             .build();

// Create bean and set values
MyBean myBean = new MyBean();
myBean.setId(1);
myBean.setFirstName("Foo");
myBean.setLastName("Bar");
myBean.setEmail("foo@bar.com");
myBean.setGender("christmasTree");
myBean.setIp("127.0.0.1");

// Map object and add to file buffer
writer.writeLine(myBean);

// Write changes to disk
writer.close();

Read csv file

CsvReader<MyBean> reader = new CsvReader.Builder<MyBean>()
                .forClass(MyBean.class)         // bean class object
                .file(new File("test.csv"))     // specify file
                .inputStream(myInputStream)        // or even stream
                .hasHeading()                   // file has headings
                .build();

// Read all lines and print to console
reader.lines().forEach(System.out::println);

Supported java versions

The parser is compatible with Java 11+.

If you need support for java 8 you must use version <= 3.1.0

There are only two things for you to do:

  1. Add to your module: requires com.github.timo_reymann.csv_parser
  2. Open your package for reflection containing bean classes like this: opens my.entities to com.github.timo_reymann.csv_parser

Thats it!

JavaDoc

If you are looking for the JavaDoc, its here

Need further information?

Just send me a mail :)

Found a bug?

Create a issue

Версии библиотеки

Версия
4.0.0
3.1.0
3.0.0
2.4.0
2.3.0
2.2.1
2.1.1
2.1.0
2.0.0
1.4.0
1.3.0
1.2.1
1.2.0
1.1.2
1.1.1
1.1.0
1.0.4
1.0.2
1.0.1
1.0