Interface CsvMapper<T>

Type Parameters:
T - the type of the object the it will map to
All Superinterfaces:
org.simpleflatmapper.map.ContextualSourceMapper<CsvRow,T>, org.simpleflatmapper.map.EnumerableMapper<CsvRowSet,T,IOException>, org.simpleflatmapper.map.SetRowMapper<CsvRow,CsvRowSet,T,IOException>, org.simpleflatmapper.map.SourceMapper<CsvRow,T>
All Known Implementing Classes:
CsvMapperFactory.DynamicCsvSetRowMapper, CsvMapperImpl

public interface CsvMapper<T> extends org.simpleflatmapper.map.SetRowMapper<CsvRow,CsvRowSet,T,IOException>
A CsvMapper will map from a 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);
}

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>>
    H
    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>>
    H
    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>>
    H
    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.
    <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>>
    H
    forEach(org.simpleflatmapper.lightningcsv.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>>
    H
    forEach(org.simpleflatmapper.lightningcsv.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.
    iterator(Reader reader)
    Will return an iterator on the reader that will return a mapped object for each row.
    iterator(Reader reader, int skip)
    Will return an iterator on the reader that will return a mapped object for each row.
    iterator(org.simpleflatmapper.lightningcsv.CsvReader reader)
    Will return an iterator on the reader that will return a mapped object for each row.
    stream(Reader reader)
    Will return a Stream of T
    stream(Reader reader, int skip)
    Will return a Stream of T.
    stream(org.simpleflatmapper.lightningcsv.CsvReader reader)
    Will return a Stream of T

    Methods inherited from interface org.simpleflatmapper.map.ContextualSourceMapper

    map

    Methods inherited from interface org.simpleflatmapper.map.EnumerableMapper

    enumerate, forEach, iterator, stream

    Methods inherited from interface org.simpleflatmapper.map.SourceMapper

    map
  • Method Details

    • forEach

      <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(Reader reader, H handle) throws IOException, org.simpleflatmapper.map.MappingException
      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.

      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();

      Type Parameters:
      H - the row handler type
      Parameters:
      reader - the reader
      handle - the callback newInstance
      Returns:
      the callback newInstance
      Throws:
      IOException - if an io error occurs
      org.simpleflatmapper.map.MappingException - if an mapping error occurs
    • forEach

      <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(org.simpleflatmapper.lightningcsv.CsvReader reader, H handle) throws IOException, org.simpleflatmapper.map.MappingException
      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.
      Type Parameters:
      H - the row handler type
      Parameters:
      reader - the reader
      handle - the callback newInstance
      Returns:
      the callback newInstance
      Throws:
      IOException - if an io error occurs
      org.simpleflatmapper.map.MappingException - if an mapping error occurs
    • forEach

      <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(Reader reader, H handle, int skip) throws IOException, org.simpleflatmapper.map.MappingException
      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.
      Type Parameters:
      H - the row handler type
      Parameters:
      reader - the reader
      handle - the callback newInstance
      skip - the number of row to skip
      Returns:
      the callback newInstance
      Throws:
      IOException - if an io error occurs
      org.simpleflatmapper.map.MappingException - if an mapping error occurs
    • forEach

      <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(Reader reader, H handle, int skip, int limit) throws IOException, org.simpleflatmapper.map.MappingException
      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.
      Type Parameters:
      H - the row handler type
      Parameters:
      reader - the reader
      handle - the callback newInstance
      skip - the number of row to skip
      limit - the number of row to process
      Returns:
      the callback newInstance
      Throws:
      IOException - if an io error occurs
      org.simpleflatmapper.map.MappingException - if an mapping error occurs
    • forEach

      <H extends org.simpleflatmapper.util.CheckedConsumer<? super T>> H forEach(org.simpleflatmapper.lightningcsv.CsvReader reader, H handle, int limit) throws IOException, org.simpleflatmapper.map.MappingException
      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.
      Type Parameters:
      H - the row handler type
      Parameters:
      reader - the reader
      handle - the callback newInstance
      limit - the number of row to process
      Returns:
      the callback newInstance
      Throws:
      IOException - if an io error occurs
      org.simpleflatmapper.map.MappingException - if an mapping error occurs
    • iterator

      Iterator<T> iterator(Reader reader) throws IOException
      Will return an iterator on the reader that will return a mapped object for each row.
      Parameters:
      reader - the reader
      Returns:
      an iterator on the file
      Throws:
      IOException - if an io error occurs
    • iterator

      Iterator<T> iterator(org.simpleflatmapper.lightningcsv.CsvReader reader) throws IOException
      Will return an iterator on the reader that will return a mapped object for each row.
      Parameters:
      reader - the reader
      Returns:
      an iterator on the file
      Throws:
      IOException - if an io error occurs
    • iterator

      Iterator<T> iterator(Reader reader, int skip) throws IOException
      Will return an iterator on the reader that will return a mapped object for each row.
      Parameters:
      reader - the reader
      skip - the number of row to skip
      Returns:
      an iterator on the file
      Throws:
      IOException - if an io error occurs
    • stream

      Stream<T> stream(Reader reader) throws IOException
      Will return a Stream of T
      Parameters:
      reader - the reader
      Returns:
      stream of T
      Throws:
      IOException - if an io error occurs
    • stream

      Stream<T> stream(org.simpleflatmapper.lightningcsv.CsvReader reader) throws IOException
      Will return a Stream of T
      Parameters:
      reader - the reader
      Returns:
      stream of T
      Throws:
      IOException - if an io error occurs
    • stream

      Stream<T> stream(Reader reader, int skip) throws IOException
      Will return a Stream of T.
      Parameters:
      reader - the reader
      skip - the number of row to skip
      Returns:
      stream of T
      Throws:
      IOException - if an io error occurs