Package org.orekit.data
Class DataSource
- java.lang.Object
-
- org.orekit.data.DataSource
-
public class DataSource extends Object
Container associating a name with a stream or reader that can be opened lazily.This association and the lazy-opening are useful in different cases:
- when
crawlinga directory tree to select data to be loaded by aDataLoader, the files that are not meaningful for the loader can be ignored and not opened at all - when
data filteringis used, the raw stream can be opened by the filter only if the upper level filtered stream is opened - when opening a stream for loading the data it provides, the opening
and closing actions can be grouped in Orekit internal code using a
try with resourcesclause so closing is done properly even in case of exception - if some pre-reading of the first few bytes or characters are needed to decide how to
load data (as in
LexicalAnalyzerSelector), then the stream can be opened, buffered and rewound and a fake open method used to return the already open stream so atry with resourcesclause 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'sopenStreamOnceoropenReaderOncemethods are called several times or are both called separately. This is particularly true for network-based streams.- Since:
- 9.2
- Author:
- Luc Maisonobe
- See Also:
DataFilter
- when
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDataSource.OpenerInterface for lazy-opening data streams one time.static interfaceDataSource.ReaderOpenerInterface for lazy-opening a characters stream one time.static interfaceDataSource.StreamOpenerInterface for lazy-opening a binary stream one time.
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetName()Get the name of the data.DataSource.OpenergetOpener()Get the data stream opener.
-
-
-
Constructor Detail
-
DataSource
public DataSource(String name, DataSource.StreamOpener streamOpener)
Complete constructor.- Parameters:
name- data namestreamOpener- opener for the data stream
-
DataSource
public DataSource(String name, DataSource.ReaderOpener readerOpener)
Complete constructor.- Parameters:
name- data namereaderOpener- opener for characters reader
-
DataSource
public DataSource(String fileName)
Build an instance from file name only.- Parameters:
fileName- name of the file- Since:
- 11.0
-
DataSource
public DataSource(File file)
Build an instance from a file on the local file system.- Parameters:
file- file- Since:
- 11.0
-
DataSource
public DataSource(URI uri)
Build an instance from URI only.- Parameters:
uri- URI of the file- Since:
- 11.0
-
-
Method Detail
-
getName
public String getName()
Get the name of the data.- Returns:
- name of the data
-
getOpener
public DataSource.Opener getOpener()
Get the data stream opener.- Returns:
- data stream opener
-
-