Class YamlConfiguration
- All Implemented Interfaces:
Configuration,ConfigurationSection,LoadableConfiguration
- Direct Known Subclasses:
YamlFile
Configuration which saves the configuration in Yaml.
Note that this implementation is not synchronized.- Author:
- Bukkit, Carleslc
- See Also:
-
Field Summary
FieldsFields inherited from class org.simpleyaml.configuration.MemoryConfiguration
defaults, optionsFields inherited from class org.simpleyaml.configuration.MemorySection
map -
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyYamlConfiguration.YamlConfiguration(Configuration defaults) Creates an emptyYamlConfigurationusing the specifiedConfigurationas a source for all default values.YamlConfiguration(Configuration defaults, YamlImplementation yamlImplementation) YamlConfiguration(YamlImplementation yamlImplementation) -
Method Summary
Modifier and TypeMethodDescriptiondump()Dump the configuration values without the header to a string.voidDump the configuration values without the header.Gets the requested Object by path, returning a default value if not found.voidLoads this configuration from the specified file.voidload(InputStream stream) Deprecated.voidDeprecated.this method loads the entire file into memory, for larger files please useload(SupplierIO.Reader)voidload(SupplierIO.InputStream streamSupplier) Loads this configuration from the specified stream.voidload(SupplierIO.Reader readerSupplier) Loads thisYamlConfigurationfrom the specified reader.static YamlConfigurationloadConfiguration(File file) Creates a newYamlConfiguration, loading from the given file.static YamlConfigurationloadConfiguration(InputStream stream) Deprecated.this method loads the entire file into memory, for larger files please useload(SupplierIO.InputStream)static YamlConfigurationloadConfiguration(Reader reader) Deprecated.this method loads the entire file into memory, for larger files please useload(SupplierIO.Reader)static YamlConfigurationloadConfiguration(SupplierIO.InputStream streamSupplier) Creates a newYamlConfiguration, loading from the given input stream.static YamlConfigurationloadConfiguration(SupplierIO.Reader readerSupplier) Creates a newYamlConfiguration, loading from the given reader.static YamlConfigurationloadConfigurationFromString(String contents) Creates a newYamlConfiguration, loading from the specified string contents.voidloadFromString(String contents) Loads thisYamlConfigurationfrom the specified string.protected voidloadHeader(Reader reader) options()Gets theConfigurationOptionsfor thisConfiguration.voidSave the configuration values including the header.Save the configuration values including the header to a string.voidSets the specified path to the given value.voidset(String path, Object value, QuoteStyle quoteStyle) Sets the specified path to the given value.voidsetImplementation(YamlImplementation yamlImplementation) Methods inherited from class org.simpleyaml.configuration.file.FileConfiguration
buildHeader, load, save, saveMethods inherited from class org.simpleyaml.configuration.MemoryConfiguration
addDefault, addDefaults, addDefaults, getDefaults, getParent, setDefaultsMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
-
yamlImplementation
-
-
Constructor Details
-
YamlConfiguration
public YamlConfiguration()Creates an emptyYamlConfiguration. -
YamlConfiguration
Creates an emptyYamlConfigurationusing the specifiedConfigurationas a source for all default values.- Parameters:
defaults- default values
-
YamlConfiguration
-
YamlConfiguration
-
-
Method Details
-
getImplementation
-
setImplementation
-
saveToString
Save the configuration values including the header to a string.- Returns:
- a String containing this configuration.
- Throws:
IOException- when the contents cannot be written for any reason
-
save
Save the configuration values including the header.- Specified by:
savein interfaceLoadableConfiguration- Overrides:
savein classFileConfiguration- Parameters:
writer- where to save this configuration- Throws:
IOException- when the contents cannot be written for any reason- See Also:
-
dump
Dump the configuration values without the header to a string.- Throws:
IOException- when the contents cannot be written for any reason- See Also:
-
dump
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(SupplierIO.Reader readerSupplier) throws IOException, InvalidConfigurationException Loads thisYamlConfigurationfrom 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.InvalidConfigurationException- Thrown when the reader does not represent a valid Configuration.IllegalArgumentException- Thrown when reader is null.
-
loadHeader
- Throws:
IOException
-
loadConfiguration
public static YamlConfiguration loadConfiguration(SupplierIO.Reader readerSupplier) throws IOException Creates a newYamlConfiguration, 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 nullIOException- if cannot load configuration
-
loadConfiguration
Creates a newYamlConfiguration, loading from the given file.This method will use the
options()charsetencoding, which defaults to UTF8.- Parameters:
file- Input file- Returns:
- Resulting configuration
- Throws:
IllegalArgumentException- if file is nullIOException- if cannot load configuration
-
load
public void load(File file) throws FileNotFoundException, IOException, 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()charsetencoding, which defaults to UTF8.- Overrides:
loadin classFileConfiguration- 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.InvalidConfigurationException- Thrown when the given file is not a valid Configuration.IllegalArgumentException- Thrown when file is null.
-
loadConfigurationFromString
Creates a newYamlConfiguration, 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.InvalidConfigurationException- Thrown when the contents does not represent a valid Configuration.IllegalArgumentException- Thrown when contents is null.
-
loadFromString
Loads thisYamlConfigurationfrom 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.InvalidConfigurationException- Thrown when the contents does not represent a valid Configuration.IllegalArgumentException- Thrown when contents is null.
-
loadConfiguration
public static YamlConfiguration loadConfiguration(SupplierIO.InputStream streamSupplier) throws IOException Creates a newYamlConfiguration, 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:
InvalidConfigurationException- if input stream is not a valid Configuration.IllegalArgumentException- if stream is nullIOException- if cannot load configuration
-
load
public void load(SupplierIO.InputStream streamSupplier) throws IOException, 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()charsetencoding, 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.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 useload(SupplierIO.InputStream)Creates a newYamlConfiguration, loading from the given stream.This method will use the
options()charsetencoding, which defaults to UTF8.- Parameters:
stream- Input stream- Returns:
- Resulting configuration
- Throws:
IllegalArgumentException- if stream is nullIOException- if cannot load configuration- See Also:
-
load
Deprecated.this method loads the entire file into memory, for larger files please useload(SupplierIO.InputStream)Description copied from class:FileConfigurationLoads 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
FileConfiguration.options()charsetencoding, which defaults to UTF8.- Overrides:
loadin classFileConfiguration- Parameters:
stream- Stream to load from- Throws:
IOException- Thrown when the given file cannot be read.InvalidConfigurationException- Thrown when the given file is not a valid Configuration.- See Also:
-
loadConfiguration
Deprecated.this method loads the entire file into memory, for larger files please useload(SupplierIO.Reader)Creates a newYamlConfiguration, loading from the given reader.- Parameters:
reader- input reader- Returns:
- resulting configuration
- Throws:
IllegalArgumentException- if stream is nullIOException- if cannot load configuration- See Also:
-
load
Deprecated.this method loads the entire file into memory, for larger files please useload(SupplierIO.Reader)Description copied from class:FileConfigurationLoads this configuration 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.
- Specified by:
loadin interfaceLoadableConfiguration- Overrides:
loadin classFileConfiguration- Parameters:
reader- the reader to load from- Throws:
IOException- Thrown when underlying reader throws an IOException.InvalidConfigurationException- Thrown when the reader does not represent a valid Configuration.- See Also:
-
set
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 toset(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 storeConfigurations orConfigurationSections, please useMemorySection.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
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 orConfigurationSections, please useMemorySection.createSection(String)for that.- Specified by:
setin interfaceConfigurationSection- Overrides:
setin classMemorySection- Parameters:
path- Path of the object to set.value- New value to set the path to.
-
get
Description copied from interface:ConfigurationSectionGets the requested Object by path, returning a default value if not found.If the Object does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Specified by:
getin interfaceConfigurationSection- Overrides:
getin classMemorySection- Parameters:
path- Path of the Object to get.def- The default value to return if the path is not found.- Returns:
- Requested Object.
-
options
Description copied from interface:ConfigurationGets theConfigurationOptionsfor thisConfiguration.All setters through this method are chainable.
- Specified by:
optionsin interfaceConfiguration- Overrides:
optionsin classFileConfiguration- Returns:
- Options for this configuration
-
load(SupplierIO.InputStream)