Class FileConfiguration

java.lang.Object
All Implemented Interfaces:
Configuration, ConfigurationSection
Direct Known Subclasses:
YamlConfiguration

public abstract class FileConfiguration
extends MemoryConfiguration
This is a base class for all File based implementations of Configuration
  • Constructor Details

    • FileConfiguration

      public FileConfiguration()
      Creates an empty FileConfiguration with no default values.
    • FileConfiguration

      public FileConfiguration​(@Nullable @Nullable Configuration defaults)
      Creates an empty FileConfiguration using the specified Configuration as a source for all default values.
      Parameters:
      defaults - Default value provider
  • Method Details

    • save

      public void save​(@NotNull @NotNull java.io.File file) throws java.io.IOException
      Saves this FileConfiguration to the specified location.

      If the file does not exist, it will be created. If already exists, it will be overwritten. If it cannot be overwritten or created, an exception will be thrown.

      This method will save using the system default encoding, or possibly using UTF8.

      Parameters:
      file - File to save to.
      Throws:
      java.io.IOException - Thrown when the given file cannot be written to for any reason.
      java.lang.IllegalArgumentException - Thrown when file is null.
    • save

      public void save​(@NotNull @NotNull java.lang.String file) throws java.io.IOException
      Saves this FileConfiguration to the specified location.

      If the file does not exist, it will be created. If already exists, it will be overwritten. If it cannot be overwritten or created, an exception will be thrown.

      This method will save using the system default encoding, or possibly using UTF8.

      Parameters:
      file - File to save to.
      Throws:
      java.io.IOException - Thrown when the given file cannot be written to for any reason.
      java.lang.IllegalArgumentException - Thrown when file is null.
    • saveToString

      @NotNull public abstract @NotNull java.lang.String saveToString()
      Saves this FileConfiguration to a string, and returns it.
      Returns:
      String containing this configuration.
    • load

      public void load​(@NotNull @NotNull java.io.File file) throws java.io.FileNotFoundException, java.io.IOException, InvalidConfigurationException
      Loads this FileConfiguration from the specified location.

      All the values contained within this configuration will be removed, leaving only settings and defaults, and the new values will be loaded from the given file.

      If the file cannot be loaded for any reason, an exception will be thrown.

      Parameters:
      file - File to load from.
      Throws:
      java.io.FileNotFoundException - Thrown when the given file cannot be opened.
      java.io.IOException - Thrown when the given file cannot be read.
      InvalidConfigurationException - Thrown when the given file is not a valid Configuration.
      java.lang.IllegalArgumentException - Thrown when file is null.
    • load

      public void load​(@NotNull @NotNull java.io.Reader reader) throws java.io.IOException, InvalidConfigurationException
      Loads this FileConfiguration from the specified reader.

      All the values contained within this configuration will be removed, leaving only settings and defaults, and the new values will be loaded from the given stream.

      Parameters:
      reader - the reader to load from
      Throws:
      java.io.IOException - thrown when underlying reader throws an IOException
      InvalidConfigurationException - thrown when the reader does not represent a valid Configuration
      java.lang.IllegalArgumentException - thrown when reader is null
    • load

      public void load​(@NotNull @NotNull java.lang.String file) throws java.io.FileNotFoundException, java.io.IOException, InvalidConfigurationException
      Loads this FileConfiguration from the specified location.

      All the values contained within this configuration will be removed, leaving only settings and defaults, and the new values will be loaded from the given file.

      If the file cannot be loaded for any reason, an exception will be thrown.

      Parameters:
      file - File to load from.
      Throws:
      java.io.FileNotFoundException - Thrown when the given file cannot be opened.
      java.io.IOException - Thrown when the given file cannot be read.
      InvalidConfigurationException - Thrown when the given file is not a valid Configuration.
      java.lang.IllegalArgumentException - Thrown when file is null.
    • loadFromString

      public abstract void loadFromString​(@NotNull @NotNull java.lang.String contents) throws InvalidConfigurationException
      Loads this FileConfiguration from the specified string, as opposed to from file.

      All the values contained within this configuration will be removed, leaving only settings and defaults, and the new values will be loaded from the given string.

      If the string is invalid in any way, an exception will be thrown.

      Parameters:
      contents - Contents of a Configuration to load.
      Throws:
      InvalidConfigurationException - Thrown if the specified string is invalid.
      java.lang.IllegalArgumentException - Thrown if contents is null.
    • buildHeader

      @NotNull protected abstract @NotNull java.lang.String buildHeader()
      Compiles the header for this FileConfiguration and returns the result.

      This will use the header from options() -> FileConfigurationOptions.header(), respecting the rules of FileConfigurationOptions.copyHeader() if set.

      Returns:
      Compiled header
    • options

      @NotNull public @NotNull FileConfigurationOptions options()
      Description copied from interface: Configuration
      Gets the ConfigurationOptions for this Configuration.

      All setters through this method are chainable.

      Specified by:
      options in interface Configuration
      Overrides:
      options in class MemoryConfiguration
      Returns:
      Options for this configuration