All Implemented Interfaces:
Configuration, ConfigurationSection
Direct Known Subclasses:
YamlConfiguration

public abstract class FileConfiguration extends MemoryConfiguration
Represents a base class for all file-based implementations of a memory configuration.

Synchronized with the commit on 24-November-2024.

  • Constructor Details

    • FileConfiguration

      protected FileConfiguration()
      Constructs an empty file configuration with no default values.
      See Also:
    • FileConfiguration

      protected FileConfiguration(@Nullable @Nullable Configuration defs)
      Constructs an empty file configuration using the given configuration as a source for all default values.
      Parameters:
      defs - The default value provider configuration.
      See Also:
  • Method Details

    • save

      public final void save(@NotNull @NotNull File file) throws IOException
      Saves this file configuration to the given file.

      If the given file does not exist, it will attempt to be created. If it already exists, any contents will be overwritten, regardless of the old or new contents. If it cannot be created or overwritten, an I/O exception will be thrown.

      This method will save using the UTF-8 charset.

      Parameters:
      file - The file to save to.
      Throws:
      IOException - If this file configuration cannot be written.
      See Also:
    • save

      public final void save(@NotNull @NotNull String path) throws IOException
      Saves this file configuration to the given file.

      If the file at the given path does not exist, it will attempt to be created. If it already exists, any contents will be overwritten, regardless of the old or new contents. If it cannot be created or overwritten, an I/O exception will be thrown.

      This method will save using the UTF-8 charset.

      Parameters:
      path - The path of the file to save to.
      Throws:
      IOException - If this file configuration cannot be written.
      See Also:
    • saveToString

      @NotNull public abstract @NotNull String saveToString()
      Converts this file configuration to a string.
      Returns:
      A string representing this file configuration.
    • load

      public final void load(@NotNull @NotNull Reader reader) throws IOException, InvalidConfigurationException
      Loads this file configuration from the given reader.

      All values contained in-memory in this file configuration will be removed, leaving only the file configuration options as well as any defaults. The new values will be loaded into memory from the given reader.

      Parameters:
      reader - The reader used to load this file configuration.
      Throws:
      IOException - If the given reader encounters an error.
      InvalidConfigurationException - If the data in the reader cannot be parsed as a file configuration.
      See Also:
    • load

      public final void load(@NotNull @NotNull File file) throws IOException, InvalidConfigurationException
      Loads this file configuration from the given file.

      All values contained in-memory in this file configuration will be removed, leaving only the file configuration options as well as any defaults. The new values will be loaded into memory from the given file.

      Parameters:
      file - The file used to load this file configuration.
      Throws:
      IOException - If the given file cannot be read.
      InvalidConfigurationException - If the data in the file cannot be parsed as a file configuration.
      See Also:
    • load

      public final void load(@NotNull @NotNull String path) throws IOException, InvalidConfigurationException
      Loads this file configuration from the file at the given path.

      All values contained in-memory in this file configuration will be removed, leaving only the file configuration options as well as any defaults. The new values will be loaded into memory from the file at the given path.

      Parameters:
      path - The path of the file to load from.
      Throws:
      IOException - If the file cannot be read.
      InvalidConfigurationException - If the data in the file cannot be parsed as a file configuration.
      See Also:
    • loadFromString

      public abstract void loadFromString(@NotNull @NotNull String data) throws InvalidConfigurationException
      Loads this file configuration from the given string.

      All values contained in-memory in this file configuration will be removed, leaving only the file configuration options as well as any defaults. The new values will be loaded into memory from the given string.

      Parameters:
      data - The string representation of the file configuration data to load.
      Throws:
      InvalidConfigurationException - If the given string cannot be parsed as a file configuration.
    • getOptions

      @NotNull public @NotNull FileConfigurationOptions getOptions()
      Gets the options for this configuration.

      All setters through this method are chainable.

      Specified by:
      getOptions in interface Configuration
      Overrides:
      getOptions in class MemoryConfiguration
      Returns:
      The options for this configuration.