Class PropertiesFileConfiguration

All Implemented Interfaces:
Cloneable, Configuration, EventSource, FileBasedConfiguration, ImmutableConfiguration, FileBased, FileLocatorAware, SynchronizerSupport

public class PropertiesFileConfiguration extends PropertiesConfiguration
This class extends a PropertiesConfiguration by the means for an underlying file as well as optionally automatically saving the configuration in case of changes. When automatically saving, each change will immediately lead to a save try. Saving will be suspended while the configuration file is being loaded or already saved.
The default for the list delimiter is ,.
  • Field Details

    • fileHandler

      protected final FileHandler fileHandler
      The handler for the configuration file.
    • streamUrl

      protected final URL streamUrl
      The URL of a stream; the file handler does not have one in case of an input stream.
  • Constructor Details

    • PropertiesFileConfiguration

      public PropertiesFileConfiguration(String file, Logger autosaveLogger) throws ConfigurationException
      Creates a new properties configuration based on the designated file and loads the configuration if the file exists. If a logger is provided, changes of the configuration will be automatically saved to the underlying file, the file will be created if required. Problems when saving will be logged appropriately.
      Parameters:
      file - The file to base the properties configuration on.
      autosaveLogger - Whether to automatically save changes to the underlying file. If so, problems will be logged to this logger. Use null to not automatically save changes.
      Throws:
      ConfigurationException - If loading the configuration from the designated file fails, a ConfigurationException will be thrown.
    • PropertiesFileConfiguration

      public PropertiesFileConfiguration(File file, Logger autosaveLogger) throws ConfigurationException
      Creates a new properties configuration based on the designated file and loads the configuration if the file exists. If a logger is provided, changes of the configuration will be automatically saved to the underlying file, the file will be created if required. Problems when saving will be logged appropriately.
      Parameters:
      file - The file to base the properties configuration on.
      autosaveLogger - Whether to automatically save changes to the underlying file. If so, problems will be logged to this logger. Use null to not automatically save changes.
      Throws:
      ConfigurationException - If loading the configuration from the designated file fails, the file cannot be read or the configuration should be automatically saved but the file cannot be written, a ConfigurationException will be thrown.
    • PropertiesFileConfiguration

      public PropertiesFileConfiguration(URL file, Logger autosaveLogger) throws ConfigurationException
      Creates a new properties configuration based on the designated file and loads the configuration. The file has to exist. If a logger is provided, changes of the configuration will be automatically saved to the underlying file. Problems when saving will be logged appropriately.
      Parameters:
      file - The file to base the properties configuration on.
      autosaveLogger - Whether to automatically save changes to the underlying file. If so, problems will be logged to this logger. Use null to not automatically save changes.
      Throws:
      ConfigurationException - If loading the configuration from the designated file fails, a ConfigurationException will be thrown. If the file cannot be read or the configuration should be automatically saved but the file cannot be written, the ConfigurationException will wrap a FileNotFoundException.
    • PropertiesFileConfiguration

      public PropertiesFileConfiguration(URL url, InputStream stream) throws ConfigurationException
      Creates a new properties configuration based on the designated URL and loads the configuration from the designated stream. Autosaving is not possible since the stream is not an output stream.
      Parameters:
      url - The URL specifying the properties file. This is merely for information purpose. If you do not have an URL use PropertiesConfiguration directly.
      stream - The input stream to read the configuration from.
      Throws:
      ConfigurationException - If loading the configuration from the designated file fails, a ConfigurationException will be thrown.
  • Method Details

    • getFileUrl

      public URL getFileUrl()
      Gets the URL of the underlying properties file.
      Returns:
      The URL of the underlying properties file.
    • load

      public void load() throws ConfigurationException
      Loads the configuration from the underlying properties file.
      Throws:
      ConfigurationException - If there are problems loading the configuration from the underlying properties file, a ConfigurationException will be thrown.
    • save

      public void save() throws ConfigurationException
      Saves the configuration to the underlying properties file.
      Throws:
      ConfigurationException - If there are problems saving the configuration to the underlying properties file, a ConfigurationException will be thrown.