Class YamlConfiguration

java.lang.Object
org.simpleyaml.configuration.MemorySection
org.simpleyaml.configuration.MemoryConfiguration
org.simpleyaml.configuration.file.FileConfiguration
org.simpleyaml.configuration.file.YamlConfiguration
All Implemented Interfaces:
org.simpleyaml.configuration.Configuration, org.simpleyaml.configuration.ConfigurationSection, org.simpleyaml.configuration.LoadableConfiguration
Direct Known Subclasses:
YamlFile

public class YamlConfiguration extends org.simpleyaml.configuration.file.FileConfiguration
An implementation of Configuration which saves the configuration in Yaml. Note that this implementation is not synchronized.
Author:
Bukkit, Carleslc
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     

    Fields inherited from class org.simpleyaml.configuration.MemoryConfiguration

    defaults, options

    Fields inherited from class org.simpleyaml.configuration.MemorySection

    map
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty YamlConfiguration.
    YamlConfiguration(org.simpleyaml.configuration.Configuration defaults)
    Creates an empty YamlConfiguration using the specified Configuration as a source for all default values.
    YamlConfiguration(org.simpleyaml.configuration.Configuration defaults, YamlImplementation yamlImplementation)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Dump the configuration values without the header to a string.
    void
    dump(Writer writer)
    Dump the configuration values without the header.
    get(String path, Object def)
     
     
    void
    load(File file)
    Loads this configuration from the specified file.
    void
    load(InputStream stream)
    Deprecated.
    this method loads the entire file into memory, for larger files please use load(SupplierIO.InputStream)
    void
    load(Reader reader)
    Deprecated.
    this method loads the entire file into memory, for larger files please use load(SupplierIO.Reader)
    void
    load(org.simpleyaml.utils.SupplierIO.InputStream streamSupplier)
    Loads this configuration from the specified stream.
    void
    load(org.simpleyaml.utils.SupplierIO.Reader readerSupplier)
    Loads this YamlConfiguration from the specified reader.
    Creates a new YamlConfiguration, loading from the given file.
    Deprecated.
    this method loads the entire file into memory, for larger files please use load(SupplierIO.InputStream)
    Deprecated.
    this method loads the entire file into memory, for larger files please use load(SupplierIO.Reader)
    loadConfiguration(org.simpleyaml.utils.SupplierIO.InputStream streamSupplier)
    Creates a new YamlConfiguration, loading from the given input stream.
    loadConfiguration(org.simpleyaml.utils.SupplierIO.Reader readerSupplier)
    Creates a new YamlConfiguration, loading from the given reader.
    Creates a new YamlConfiguration, loading from the specified string contents.
    void
    Loads this YamlConfiguration from the specified string.
    protected void
     
     
    void
    save(Writer writer)
    Save the configuration values including the header.
    Save the configuration values including the header to a string.
    void
    set(String path, Object value)
    Sets the specified path to the given value.
    void
    set(String path, Object value, QuoteStyle quoteStyle)
    Sets the specified path to the given value.
    void
     

    Methods inherited from class org.simpleyaml.configuration.file.FileConfiguration

    buildHeader, load, save, save

    Methods inherited from class org.simpleyaml.configuration.MemoryConfiguration

    addDefault, addDefaults, addDefaults, getDefaults, getParent, setDefaults

    Methods inherited from class org.simpleyaml.configuration.MemorySection

    contains, createPath, createPath, createSection, createSection, get, getBoolean, getBoolean, getBooleanList, getByte, getByte, getByteList, getCharacter, getCharacter, getCharacterList, getConfigurationSection, getCurrentPath, getDefault, getDefaultSection, getDouble, getDouble, getDoubleList, getFloat, getFloat, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getMapValues, getName, getRoot, getShort, getShort, getShortList, getString, getString, getStringList, getValues, isBoolean, isByte, isCharacter, isConfigurationSection, isDouble, isEmpty, isFloat, isInt, isList, isLong, isPrimitiveWrapper, isSet, isShort, isString, mapChildrenKeys, mapChildrenValues, size, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.simpleyaml.configuration.ConfigurationSection

    contains, createSection, createSection, get, getBoolean, getBoolean, getBooleanList, getByte, getByte, getByteList, getCharacter, getCharacter, getCharacterList, getConfigurationSection, getCurrentPath, getDefaultSection, getDouble, getDouble, getDoubleList, getFloat, getFloat, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getMapValues, getName, getRoot, getShort, getShort, getShortList, getString, getString, getStringList, getValues, isBoolean, isByte, isCharacter, isConfigurationSection, isDouble, isEmpty, isFloat, isInt, isList, isLong, isSet, isShort, isString, remove, size
  • Field Details

  • Constructor Details

    • YamlConfiguration

      public YamlConfiguration()
      Creates an empty YamlConfiguration.
    • YamlConfiguration

      public YamlConfiguration(org.simpleyaml.configuration.Configuration defaults)
      Creates an empty YamlConfiguration using the specified Configuration as a source for all default values.
      Parameters:
      defaults - default values
    • YamlConfiguration

      public YamlConfiguration(YamlImplementation yamlImplementation)
    • YamlConfiguration

      public YamlConfiguration(org.simpleyaml.configuration.Configuration defaults, YamlImplementation yamlImplementation)
  • Method Details

    • getImplementation

      public YamlImplementation getImplementation()
    • setImplementation

      public void setImplementation(YamlImplementation yamlImplementation)
    • saveToString

      public String saveToString() throws IOException
      Save the configuration values including the header to a string.
      Throws:
      IOException - when the contents cannot be written for any reason
    • save

      public void save(Writer writer) throws IOException
      Save the configuration values including the header.
      Specified by:
      save in interface org.simpleyaml.configuration.LoadableConfiguration
      Overrides:
      save in class org.simpleyaml.configuration.file.FileConfiguration
      Parameters:
      writer - where to save this configuration
      Throws:
      IOException - when the contents cannot be written for any reason
      See Also:
    • dump

      public String dump() throws IOException
      Dump the configuration values without the header to a string.
      Throws:
      IOException - when the contents cannot be written for any reason
      See Also:
    • dump

      public void dump(Writer writer) throws IOException
      Dump the configuration values without the header.
      Parameters:
      writer - where to save this configuration
      Throws:
      IOException - when the contents cannot be written for any reason
      See Also:
    • load

      public void load(org.simpleyaml.utils.SupplierIO.Reader readerSupplier) throws IOException, org.simpleyaml.exceptions.InvalidConfigurationException
      Loads this YamlConfiguration 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.

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

      Parameters:
      readerSupplier - a function providing the reader to load from (new instance)
      Throws:
      IOException - Thrown when underlying reader throws an IOException.
      org.simpleyaml.exceptions.InvalidConfigurationException - Thrown when the reader does not represent a valid Configuration.
      IllegalArgumentException - Thrown when reader is null.
    • loadHeader

      protected void loadHeader(Reader reader) throws IOException
      Throws:
      IOException
    • loadConfiguration

      public static YamlConfiguration loadConfiguration(org.simpleyaml.utils.SupplierIO.Reader readerSupplier) throws IOException
      Creates a new YamlConfiguration, loading from the given reader.
      Parameters:
      readerSupplier - a function providing the reader to load from (new instance)
      Returns:
      resulting configuration
      Throws:
      IllegalArgumentException - if stream is null
      IOException - if cannot load configuration
    • loadConfiguration

      public static YamlConfiguration loadConfiguration(File file) throws IOException
      Creates a new YamlConfiguration, loading from the given file.

      This method will use the options() charset encoding, which defaults to UTF8.

      Parameters:
      file - Input file
      Returns:
      Resulting configuration
      Throws:
      IllegalArgumentException - if file is null
      IOException - if cannot load configuration
    • load

      public void load(File file) throws FileNotFoundException, IOException, org.simpleyaml.exceptions.InvalidConfigurationException
      Loads this configuration from the specified 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 file.

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

      This method will use the options() charset encoding, which defaults to UTF8.

      Overrides:
      load in class org.simpleyaml.configuration.file.FileConfiguration
      Parameters:
      file - File to load from.
      Throws:
      FileNotFoundException - Thrown when the given file cannot be opened.
      IOException - Thrown when the given file cannot be read.
      org.simpleyaml.exceptions.InvalidConfigurationException - Thrown when the given file is not a valid Configuration.
      IllegalArgumentException - Thrown when file is null.
    • loadConfigurationFromString

      public static YamlConfiguration loadConfigurationFromString(String contents) throws IOException
      Creates a new YamlConfiguration, loading from the specified string contents.

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

      Parameters:
      contents - the contents to load from
      Throws:
      IOException - Thrown when underlying reader throws an IOException.
      org.simpleyaml.exceptions.InvalidConfigurationException - Thrown when the contents does not represent a valid Configuration.
      IllegalArgumentException - Thrown when contents is null.
    • loadFromString

      public void loadFromString(String contents) throws IOException
      Loads this YamlConfiguration from the specified string.

      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.

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

      Parameters:
      contents - the contents to load from
      Throws:
      IOException - Thrown when underlying reader throws an IOException.
      org.simpleyaml.exceptions.InvalidConfigurationException - Thrown when the contents does not represent a valid Configuration.
      IllegalArgumentException - Thrown when contents is null.
    • loadConfiguration

      public static YamlConfiguration loadConfiguration(org.simpleyaml.utils.SupplierIO.InputStream streamSupplier) throws IOException
      Creates a new YamlConfiguration, loading from the given input stream.

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

      Parameters:
      streamSupplier - a function providing the stream to load from (new instance)
      Returns:
      resulting configuration
      Throws:
      org.simpleyaml.exceptions.InvalidConfigurationException - if input stream is not a valid Configuration.
      IllegalArgumentException - if stream is null
      IOException - if cannot load configuration
    • load

      public void load(org.simpleyaml.utils.SupplierIO.InputStream streamSupplier) throws IOException, org.simpleyaml.exceptions.InvalidConfigurationException
      Loads this configuration from the specified stream.

      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.

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

      This method will use the options() charset encoding, which defaults to UTF8.

      Parameters:
      streamSupplier - a function providing the stream to load from (new instance)
      Throws:
      IOException - Thrown when the given file cannot be read.
      org.simpleyaml.exceptions.InvalidConfigurationException - Thrown when the given file is not a valid Configuration.
      IllegalArgumentException - Thrown when stream is null.
      See Also:
    • loadConfiguration

      @Deprecated public static YamlConfiguration loadConfiguration(InputStream stream) throws IOException
      Deprecated.
      this method loads the entire file into memory, for larger files please use load(SupplierIO.InputStream)
      Creates a new YamlConfiguration, loading from the given stream.

      This method will use the options() charset encoding, which defaults to UTF8.

      Parameters:
      stream - Input stream
      Returns:
      Resulting configuration
      Throws:
      IllegalArgumentException - if stream is null
      IOException - if cannot load configuration
      See Also:
    • load

      @Deprecated public void load(InputStream stream) throws IOException, org.simpleyaml.exceptions.InvalidConfigurationException
      Deprecated.
      this method loads the entire file into memory, for larger files please use load(SupplierIO.InputStream)
      Overrides:
      load in class org.simpleyaml.configuration.file.FileConfiguration
      Throws:
      IOException
      org.simpleyaml.exceptions.InvalidConfigurationException
      See Also:
    • loadConfiguration

      @Deprecated public static YamlConfiguration loadConfiguration(Reader reader) throws IOException
      Deprecated.
      this method loads the entire file into memory, for larger files please use load(SupplierIO.Reader)
      Creates a new YamlConfiguration, loading from the given reader.
      Parameters:
      reader - input reader
      Returns:
      resulting configuration
      Throws:
      IllegalArgumentException - if stream is null
      IOException - if cannot load configuration
      See Also:
    • load

      @Deprecated public void load(Reader reader) throws IOException, org.simpleyaml.exceptions.InvalidConfigurationException
      Deprecated.
      this method loads the entire file into memory, for larger files please use load(SupplierIO.Reader)
      Specified by:
      load in interface org.simpleyaml.configuration.LoadableConfiguration
      Overrides:
      load in class org.simpleyaml.configuration.file.FileConfiguration
      Throws:
      IOException
      org.simpleyaml.exceptions.InvalidConfigurationException
      See Also:
    • set

      public void set(String path, Object value, QuoteStyle quoteStyle)
      Sets the specified path to the given value.

      The value will be represented with the specified quote style in the configuration file.

      Any existing entry will be replaced, regardless of what the new value is.

      Null value is valid and will not remove the key, this is different to set(String, Object). Instead, a null value will be written as a yaml empty null value.

      Some implementations may have limitations on what you may store. See their individual javadocs for details. No implementations should allow you to store Configurations or ConfigurationSections, please use MemorySection.createSection(String) for that.

      Parameters:
      path - Path of the object to set.
      value - New value to set the path to.
      quoteStyle - The quote style to use.
    • set

      public void set(String path, Object value)
      Sets the specified path to the given value.

      If value is null, the entry will be removed. Any existing entry will be replaced, regardless of what the new value is.

      Some implementations may have limitations on what you may store. See their individual javadocs for details. No implementations should allow you to store Configurations or ConfigurationSections, please use MemorySection.createSection(String) for that.

      Specified by:
      set in interface org.simpleyaml.configuration.ConfigurationSection
      Overrides:
      set in class org.simpleyaml.configuration.MemorySection
      Parameters:
      path - Path of the object to set.
      value - New value to set the path to.
    • get

      public Object get(String path, Object def)
      Specified by:
      get in interface org.simpleyaml.configuration.ConfigurationSection
      Overrides:
      get in class org.simpleyaml.configuration.MemorySection
    • options

      public YamlConfigurationOptions options()
      Specified by:
      options in interface org.simpleyaml.configuration.Configuration
      Overrides:
      options in class org.simpleyaml.configuration.file.FileConfiguration