T
- the type of the object the it will map topublic interface CsvMapper<T>
CsvReader
to an object of the specified type T.
There are 2 ways to instantiate a CsvMapper
Using CsvMapperFactory
CsvMapper jdbcMapper = CsvMapperFactory
.newInstance()
.newMapper(MyClass.class);
try (FileReader reader : new FileReader(file)) {
jdbcMapper.stream(reader).forEach(System.out::println);
}
Or Using the CsvParser
DSL
try (FileReader reader : new FileReader(file)) {
CsvParser.mapTo(MyClass.class).stream(reader).forEach(System.out::println);
}
The CsvMapper can read from an Reader
or
a CsvReader
to gain more control on the csv parsing.
You can instantiate a CsvReader using the CsvParser
DSL
try (FileReader reader : new FileReader(file)) {
CsvReader csvReader = CsvParser.quote('\'').separator(';').skip(2).limit(5).reader(reader);
jdbcMapper.stream(csvReader).forEach(System.out::println);
}
CsvParser
,
CsvMapperFactory
Modifier and Type | Method and Description |
---|---|
<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> |
forEach(CsvReader reader,
H handle)
Will map each row of the content of reader to an object of type T and will pass that object to the handle via the
CheckedConsumer .handler(T t) call back. |
<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> |
forEach(CsvReader reader,
H handle,
int limit)
Will map each row of the content of reader, starting at rowStart and ending before rowEnd, to an object of type T and will pass that object to the handle via the
CheckedConsumer .handler(T t) call back. |
<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> |
forEach(Reader reader,
H handle)
Will map each row of the content of reader to an object of type T and will pass that object to the handle via the
CheckedConsumer .handler(T t) call back. |
<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> |
forEach(Reader reader,
H handle,
int skip)
Will map each row of the content of reader, starting at rowStart, to an object of type T and will pass that object to the handle via the
CheckedConsumer .handler(T t) call back. |
<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> |
forEach(Reader reader,
H handle,
int skip,
int limit)
Will map each row of the content of reader, starting at rowStart and ending before rowEnd, to an object of type T and will pass that object to the handle via the
CheckedConsumer .handler(T t) call back. |
Iterator<T> |
iterator(CsvReader reader)
Will return an iterator on the reader that will return a mapped object for each row.
|
Iterator<T> |
iterator(Reader reader)
Will return an iterator on the reader that will return a mapped object for each row.
|
Iterator<T> |
iterator(Reader reader,
int skip)
Will return an iterator on the reader that will return a mapped object for each row.
|
Stream<T> |
stream(CsvReader reader)
Will return a Stream of T
|
Stream<T> |
stream(Reader reader)
Will return a Stream of T
|
Stream<T> |
stream(Reader reader,
int skip)
Will return a Stream of T.
|
<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(Reader reader, H handle) throws IOException, org.simpleflatmapper.map.MappingException
CheckedConsumer
.handler(T t) call back.
The method will return the handler passed as an argument so you can easily chain the calls like
List<T> list = jdbcMapper.forEach(reader, new ListHandler<T>()).getList();
H
- the row handler typereader
- the readerhandle
- the callback newInstanceIOException
- if an io error occursorg.simpleflatmapper.map.MappingException
- if an mapping error occurs<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(CsvReader reader, H handle) throws IOException, org.simpleflatmapper.map.MappingException
CheckedConsumer
.handler(T t) call back.H
- the row handler typereader
- the readerhandle
- the callback newInstanceIOException
- if an io error occursorg.simpleflatmapper.map.MappingException
- if an mapping error occurs<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(Reader reader, H handle, int skip) throws IOException, org.simpleflatmapper.map.MappingException
CheckedConsumer
.handler(T t) call back.H
- the row handler typereader
- the readerhandle
- the callback newInstanceskip
- the number of row to skipIOException
- if an io error occursorg.simpleflatmapper.map.MappingException
- if an mapping error occurs<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(Reader reader, H handle, int skip, int limit) throws IOException, org.simpleflatmapper.map.MappingException
CheckedConsumer
.handler(T t) call back.H
- the row handler typereader
- the readerhandle
- the callback newInstanceskip
- the number of row to skiplimit
- the number of row to processIOException
- if an io error occursorg.simpleflatmapper.map.MappingException
- if an mapping error occurs<H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(CsvReader reader, H handle, int limit) throws IOException, org.simpleflatmapper.map.MappingException
CheckedConsumer
.handler(T t) call back.H
- the row handler typereader
- the readerhandle
- the callback newInstancelimit
- the number of row to processIOException
- if an io error occursorg.simpleflatmapper.map.MappingException
- if an mapping error occursIterator<T> iterator(Reader reader) throws IOException
reader
- the readerIOException
- if an io error occursIterator<T> iterator(CsvReader reader) throws IOException
reader
- the readerIOException
- if an io error occursIterator<T> iterator(Reader reader, int skip) throws IOException
reader
- the readerskip
- the number of row to skipIOException
- if an io error occursStream<T> stream(Reader reader) throws IOException
reader
- the readerIOException
- if an io error occursStream<T> stream(CsvReader reader) throws IOException
reader
- the readerIOException
- if an io error occursStream<T> stream(Reader reader, int skip) throws IOException
reader
- the readerskip
- the number of row to skipIOException
- if an io error occursCopyright © 2017. All rights reserved.