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 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 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 theContext
and initialization properties.protected Reader
openStream(File file)
Open aReader
for 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:DataSource
Initializes the DataSource with theContext
and initialization properties.This is invoked by the
DataImporter
after creating an instance of this class.- Specified by:
init
in 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:
getData
in 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 aReader
for the given file name- Parameters:
file
- aFile
instance- 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:DataSource
Cleans up resources of this DataSource after use.- Specified by:
close
in classDataSource<Reader>
-
-