Class FileBasedConfig


  • public class FileBasedConfig
    extends StoredConfig
    The configuration file that is stored in the file of the file system.
    • Constructor Detail

      • FileBasedConfig

        public FileBasedConfig​(File cfgLocation,
                               FS fs)
        Create a configuration with no default fallback.
        Parameters:
        cfgLocation - the location of the configuration file on the file system
        fs - the file system abstraction which will be necessary to perform certain file system operations.
      • FileBasedConfig

        public FileBasedConfig​(Config base,
                               File cfgLocation,
                               FS fs)
        The constructor
        Parameters:
        base - the base configuration file
        cfgLocation - the location of the configuration file on the file system
        fs - the file system abstraction which will be necessary to perform certain file system operations.
    • Method Detail

      • getFile

        public final File getFile()
        Get location of the configuration file on disk
        Returns:
        location of the configuration file on disk
      • load

        public void load()
                  throws IOException,
                         ConfigInvalidException
        Load the configuration from the persistent store.

        If the configuration does not exist, this configuration is cleared, and thus behaves the same as though the backing store exists, but is empty.

        Load the configuration as a Git text style configuration file.

        If the file does not exist, this configuration is cleared, and thus behaves the same as though the file exists, but is empty.

        Specified by:
        load in class StoredConfig
        Throws:
        IOException - the configuration could not be read (but does exist).
        ConfigInvalidException - the configuration is not properly formatted.
      • save

        public void save()
                  throws IOException
        Save the configuration to the persistent store.

        Save the configuration as a Git text style configuration file.

        Warning: Although this method uses the traditional Git file locking approach to protect against concurrent writes of the configuration file, it does not ensure that the file has not been modified since the last read, which means updates performed by other objects accessing the same backing file may be lost.

        Specified by:
        save in class StoredConfig
        Throws:
        IOException - the configuration could not be written.
      • clear

        public void clear()
        Clear the configuration file
        Overrides:
        clear in class StoredConfig
      • isOutdated

        public boolean isOutdated()
        Whether the currently loaded configuration file is outdated
        Returns:
        returns true if the currently loaded configuration file is older than the file on disk
      • readIncludedConfig

        protected byte[] readIncludedConfig​(String relPath)
                                     throws ConfigInvalidException
        Read the included config from the specified (possibly) relative path
        Overrides:
        readIncludedConfig in class Config
        Parameters:
        relPath - possibly relative path to the included config, as specified in this config
        Returns:
        the read bytes, or null if the included config should be ignored
        Throws:
        ConfigInvalidException - if something went wrong while reading the config
        Since:
        4.10