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.
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 and Description |
---|
FileDataSource() |
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 |
public static final String BASE_PATH
protected String basePath
protected String encoding
public void init(Context context, Properties initProps)
DataSource
Context
and
initialization properties.
This is invoked by the DataImporter
after creating an
instance of this class.
init
in class DataSource<Reader>
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
getData
in class DataSource<Reader>
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.protected Reader openStream(File file) throws FileNotFoundException, UnsupportedEncodingException
Reader
for the given file namefile
- a File
instanceFileNotFoundException
- if the File does not existUnsupportedEncodingException
- if the encoding is unsupportedpublic void close()
DataSource
close
in class DataSource<Reader>
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.