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
DataSourcewhich reads from local filesThe 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
-
-
Constructor Summary
Constructors Constructor Description FileDataSource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Cleans up resources of this DataSource after use.ReadergetData(String query)Returns a reader for the given file.voidinit(Context context, Properties initProps)Initializes the DataSource with theContextand initialization properties.protected ReaderopenStream(File file)Open aReaderfor the given file name
-
-
-
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
-
-
Method Detail
-
init
public void init(Context context, Properties initProps)
Description copied from class:DataSourceInitializes the DataSource with theContextand initialization properties.This is invoked by the
DataImporterafter creating an instance of this class.- Specified by:
initin classDataSource<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:
getDatain classDataSource<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 aReaderfor the given file name- Parameters:
file- aFileinstance- Returns:
- a Reader on the given file
- Throws:
FileNotFoundException- if the File does not existUnsupportedEncodingException- if the encoding is unsupported- Since:
- solr 1.4
-
close
public void close()
Description copied from class:DataSourceCleans up resources of this DataSource after use.- Specified by:
closein classDataSource<Reader>
-
-