Interface ICsvBeanReader

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable, ICsvReader
    All Known Implementing Classes:
    CsvBeanReader

    public interface ICsvBeanReader
    extends ICsvReader
    Interface for CSV readers reading into objects/beans.
    Author:
    Kasper B. Graversen, James Bassett
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <T> T read​(java.lang.Class<T> clazz, java.lang.String... nameMapping)
      Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields.
      <T> T read​(java.lang.Class<T> clazz, java.lang.String[] nameMapping, CellProcessor... processors)
      Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields.
      <T> T read​(T bean, java.lang.String... nameMapping)
      Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields.
      <T> T read​(T bean, java.lang.String[] nameMapping, CellProcessor... processors)
      Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields.
      • Methods inherited from interface java.io.Closeable

        close
    • Method Detail

      • read

        <T> T read​(java.lang.Class<T> clazz,
                   java.lang.String... nameMapping)
            throws java.io.IOException
        Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields.
        Type Parameters:
        T - the bean type
        Parameters:
        clazz - the type to instantiate. If the type is a class then a new instance will be created using the default no-args constructor. If the type is an interface, a proxy object which implements the interface will be created instead.
        nameMapping - an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).
        Returns:
        a populated bean or null if EOF
        Throws:
        java.io.IOException - if an I/O error occurred
        java.lang.IllegalArgumentException - if nameMapping.length != number of columns read
        java.lang.NullPointerException - if clazz or nameMapping are null
        SuperCsvException - if there was a general exception while reading/processing
        SuperCsvReflectionException - if there was an reflection exception while mapping the values to the bean
        Since:
        1.0
      • read

        <T> T read​(T bean,
                   java.lang.String... nameMapping)
            throws java.io.IOException
        Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields.
        Type Parameters:
        T - the bean type
        Parameters:
        bean - the bean to populate
        nameMapping - an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).
        Returns:
        a populated bean or null if EOF
        Throws:
        java.io.IOException - if an I/O error occurred
        java.lang.IllegalArgumentException - if nameMapping.length != number of columns read
        java.lang.NullPointerException - if bean or nameMapping are null
        SuperCsvException - if there was a general exception while reading/processing
        SuperCsvReflectionException - if there was an reflection exception while mapping the values to the bean
        Since:
        2.2.0
      • read

        <T> T read​(java.lang.Class<T> clazz,
                   java.lang.String[] nameMapping,
                   CellProcessor... processors)
            throws java.io.IOException
        Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields. Before population the data can be further processed by cell processors (as with the nameMapping array, each element in the processors array corresponds with a CSV column). A null entry in the processors array indicates no further processing is required (the unprocessed String value will be set on the bean's field).
        Type Parameters:
        T - the bean type
        Parameters:
        clazz - the type to instantiate. If the type is a class then a new instance will be created using the default no-args constructor. If the type is an interface, a proxy object which implements the interface will be created instead.
        nameMapping - an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).
        processors - an array of CellProcessors used to further process data before it is populated on the bean (each element in the processors array corresponds with a CSV column - the number of processors should match the number of columns). A null entry indicates no further processing is required (the unprocessed String value will be set on the bean's field).
        Returns:
        a populated bean or null if EOF
        Throws:
        java.io.IOException - if an I/O error occurred
        java.lang.NullPointerException - if clazz, nameMapping, or processors are null
        SuperCsvConstraintViolationException - if a CellProcessor constraint failed
        SuperCsvException - if there was a general exception while reading/processing
        SuperCsvReflectionException - if there was an reflection exception while mapping the values to the bean
        Since:
        1.0
      • read

        <T> T read​(T bean,
                   java.lang.String[] nameMapping,
                   CellProcessor... processors)
            throws java.io.IOException
        Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields. Before population the data can be further processed by cell processors (as with the nameMapping array, each element in the processors array corresponds with a CSV column). A null entry in the processors array indicates no further processing is required (the unprocessed String value will be set on the bean's field).
        Type Parameters:
        T - the bean type
        Parameters:
        bean - the bean to populate
        nameMapping - an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).
        processors - an array of CellProcessors used to further process data before it is populated on the bean (each element in the processors array corresponds with a CSV column - the number of processors should match the number of columns). A null entry indicates no further processing is required (the unprocessed String value will be set on the bean's field).
        Returns:
        a populated bean or null if EOF
        Throws:
        java.io.IOException - if an I/O error occurred
        java.lang.NullPointerException - if bean, nameMapping, or processors are null
        SuperCsvConstraintViolationException - if a CellProcessor constraint failed
        SuperCsvException - if there was a general exception while reading/processing
        SuperCsvReflectionException - if there was an reflection exception while mapping the values to the bean
        Since:
        2.2.0