org.apache.solr.handler.dataimport

## Class FileDataSource

- java.lang.Object
- - org.apache.solr.handler.dataimport.DataSource<Reader>
  - - org.apache.solr.handler.dataimport.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `BASE_PATH`
    `protected String` | `basePath` The basePath for this data source
    `protected String` | `encoding` The encoding using which the given file should be read

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileDataSource()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Cleans up resources of this DataSource after use.
    `Reader` | `getData(String query)` Returns a reader for the given file.
    `void` | `init(Context context, Properties initProps)` Initializes the DataSource with the `Context` and initialization properties.
    `protected Reader` | `openStream(File file)` Open a `Reader` for the given file name

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BASE_PATH

          public static final String BASE_PATH

      See Also:
        Constant Field Values

    - #### 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>>

    - #### openStream

          protected Reader openStream(File file)
                               throws FileNotFoundException,
                                      UnsupportedEncodingException

      Open a `Reader` for the given file name
      Parameters:
        `file` - a `File` instance
      Returns:
        a Reader on the given file
      Throws:
        `FileNotFoundException` - if the File does not exist
        `UnsupportedEncodingException` - if the encoding is unsupported
      Since:
        solr 1.4

    - #### close

          public void close()

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

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.