public class DataSource extends Object
This association and the lazy-opening are useful in different cases:
crawling
a directory tree to select data
to be loaded by a DataLoader
, the files that are not meaningful for
the loader can be ignored and not opened at alldata filtering
is used, the raw stream can
be opened by the filter only if the upper level filtered stream is openedtry
with resources
clause so closing is done properly even in case of exceptionLexicalAnalyzerSelector
),
then the stream can be opened, buffered and rewound and a fake open method used
to return the already open stream so a try with resources
clause
elsewhere works properly for closing the stream
Beware that the purpose of this class is only to delay this opening (or not open
the stream or reader at all), it is not intended to open the stream several
times and not intended to open both the binary stream and the characters reader.
Some implementations may fail if the opener
's
openStreamOnce
or openReaderOnce
methods are called several times or are both called separately. This is particularly
true for network-based streams.
DataFilter
Modifier and Type | Class and Description |
---|---|
static interface |
DataSource.Opener
Interface for lazy-opening data streams one time.
|
static interface |
DataSource.ReaderOpener
Interface for lazy-opening a characters stream one time.
|
static interface |
DataSource.StreamOpener
Interface for lazy-opening a binary stream one time.
|
Constructor and Description |
---|
DataSource(File file)
Build an instance from a file on the local file system.
|
DataSource(String fileName)
Build an instance from file name only.
|
DataSource(String name,
DataSource.ReaderOpener readerOpener)
Complete constructor.
|
DataSource(String name,
DataSource.StreamOpener streamOpener)
Complete constructor.
|
DataSource(URI uri)
Build an instance from URI only.
|
Modifier and Type | Method and Description |
---|---|
String |
getName()
Get the name of the data.
|
DataSource.Opener |
getOpener()
Get the data stream opener.
|
public DataSource(String name, DataSource.StreamOpener streamOpener)
name
- data namestreamOpener
- opener for the data streampublic DataSource(String name, DataSource.ReaderOpener readerOpener)
name
- data namereaderOpener
- opener for characters readerpublic DataSource(String fileName)
fileName
- name of the filepublic DataSource(File file)
file
- filepublic DataSource(URI uri)
uri
- URI of the filepublic String getName()
public DataSource.Opener getOpener()
Copyright © 2002-2022 CS GROUP. All rights reserved.