Class AbstractCsvDataSource<DataType>

  • Type Parameters:
    DataType - The type provided by this data source
    All Implemented Interfaces:
    DataSource<org.springframework.core.io.Resource,​DataType>

    public abstract class AbstractCsvDataSource<DataType>
    extends AbstractDataSource<org.springframework.core.io.Resource,​org.apache.commons.csv.CSVRecord,​DataType>
    AbstractCsvDataSource acts as base class for csv file data sources. It is based on Resource as selector type. The DataSource.canHandle(Object) methods checks for "csv" as file extension.

    This class uses CSVFormat for parsing the csv file.

    Since:
    3.0.0
    Author:
    Oliver Libutzki <[email protected]>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canHandle​(org.springframework.core.io.Resource resource)
      This method is called by the framework in order to determine if the DataSource is able to provide data based on the given selector.
      protected java.util.Iterator<org.apache.commons.csv.CSVRecord> getIterator​(org.springframework.core.io.Resource resource)
      Returns an iterator which traverses the source data types.
      java.lang.Class<org.springframework.core.io.Resource> getSelectorType()
      This method is called when a suitable DataSource is determined.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractCsvDataSource

        public AbstractCsvDataSource()
    • Method Detail

      • canHandle

        public boolean canHandle​(org.springframework.core.io.Resource resource)
        Description copied from interface: DataSource
        This method is called by the framework in order to determine if the DataSource is able to provide data based on the given selector. If the method returns true, DataSource.getData(Object) is called in order to obtain the data.

        canHandle is only called if the the selector is compatible with the Class returned by DataSource.getSelectorType().

        Concrete data sources should rather extend AbstractDataSource than implementing this interface directly.

        Parameters:
        resource - the selector which is used to determine the data to be provided
        Returns:
        true, if the DataSource can provide data fpr the given selector, otherweise false.
      • getSelectorType

        public java.lang.Class<org.springframework.core.io.Resource> getSelectorType()
        Description copied from interface: DataSource
        This method is called when a suitable DataSource is determined. DataSources can specify which selector types are supported.
        Returns:
        the supported selector type.
      • getIterator

        protected java.util.Iterator<org.apache.commons.csv.CSVRecord> getIterator​(org.springframework.core.io.Resource resource)
        Description copied from class: AbstractDataSource
        Returns an iterator which traverses the source data types. Each entry is processed by AbstractDataSource.mapDataSet(Object).
        Specified by:
        getIterator in class AbstractDataSource<org.springframework.core.io.Resource,​org.apache.commons.csv.CSVRecord,​DataType>
        Parameters:
        resource - the selector which is used to determine the data to be provided
        Returns:
        an iterator which reflects the provided data sets