Class 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 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 all
    • when data filtering is 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 resources clause 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 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.

    Since:
    9.2
    Author:
    Luc Maisonobe
    See Also:
    DataFilter
    • Constructor Detail

      • DataSource

        public DataSource​(String name,
                          DataSource.StreamOpener streamOpener)
        Complete constructor.
        Parameters:
        name - data name
        streamOpener - opener for the data stream
      • DataSource

        public DataSource​(String name,
                          DataSource.ReaderOpener readerOpener)
        Complete constructor.
        Parameters:
        name - data name
        readerOpener - 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