Class FileDataSource


  • public class FileDataSource
    extends DataSource<Reader>

    A DataSource which reads from local files

    The file is read with the default platform encoding. It can be overriden by specifying the encoding in solrconfig.xml

    Refer to http://wiki.apache.org/solr/DataImportHandler for more details.

    This API is experimental and may change in the future.

    Since:
    solr 1.3
    • Field Detail

      • basePath

        protected String basePath
        The basePath for this data source
      • encoding

        protected String encoding
        The encoding using which the given file should be read
    • Constructor Detail

      • FileDataSource

        public FileDataSource()
    • Method Detail

      • init

        public void init​(Context context,
                         Properties initProps)
        Description copied from class: DataSource
        Initializes the DataSource with the Context and initialization properties.

        This is invoked by the DataImporter after creating an instance of this class.

        Specified by:
        init in class DataSource<Reader>
      • getData

        public Reader getData​(String query)

        Returns a reader for the given file.

        If the given file is not absolute, we try to construct an absolute path using basePath configuration. If that fails, then the relative path is tried. If file is not found a RuntimeException is thrown.

        It is the responsibility of the calling method to properly close the returned Reader

        Specified by:
        getData in class DataSource<Reader>
        Parameters:
        query - The query string. It can be a SQL for JdbcDataSource or a URL for HttpDataSource or a file location for FileDataSource or a custom format for your own custom DataSource.
        Returns:
        Depends on the implementation. For instance JdbcDataSource returns an Iterator<Map <String,Object>>
      • close

        public void close()
        Description copied from class: DataSource
        Cleans up resources of this DataSource after use.
        Specified by:
        close in class DataSource<Reader>