public class YamlConfiguration extends FileConfiguration
Configuration
which saves the configuration in Yaml.
Note that this implementation is not synchronized.Modifier and Type | Field and Description |
---|---|
protected YamlImplementation |
yamlImplementation |
defaults, options
map
Constructor and Description |
---|
YamlConfiguration()
Creates an empty
YamlConfiguration . |
YamlConfiguration(Configuration defaults)
Creates an empty
YamlConfiguration using the specified
Configuration as a source for all default values. |
YamlConfiguration(Configuration defaults,
YamlImplementation yamlImplementation) |
YamlConfiguration(YamlImplementation yamlImplementation) |
Modifier and Type | Method and Description |
---|---|
String |
dump()
Dump the configuration values without the header to a string.
|
void |
dump(Writer writer)
Dump the configuration values without the header.
|
Object |
get(String path,
Object def)
Gets the requested Object by path, returning a default value if not
found.
|
YamlImplementation |
getImplementation() |
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(SupplierIO.InputStream streamSupplier)
Loads this configuration from the specified stream.
|
void |
load(SupplierIO.Reader readerSupplier)
Loads this
YamlConfiguration from the specified reader. |
static YamlConfiguration |
loadConfiguration(File file)
Creates a new
YamlConfiguration , loading from the given file. |
static YamlConfiguration |
loadConfiguration(InputStream stream)
Deprecated.
this method loads the entire file into memory, for larger files please use
load(SupplierIO.InputStream) |
static YamlConfiguration |
loadConfiguration(Reader reader)
Deprecated.
this method loads the entire file into memory, for larger files please use
load(SupplierIO.Reader) |
static YamlConfiguration |
loadConfiguration(SupplierIO.InputStream streamSupplier)
Creates a new
YamlConfiguration , loading from the given input stream. |
static YamlConfiguration |
loadConfiguration(SupplierIO.Reader readerSupplier)
Creates a new
YamlConfiguration , loading from the given reader. |
static YamlConfiguration |
loadConfigurationFromString(String contents)
Creates a new
YamlConfiguration , loading from the specified string contents. |
void |
loadFromString(String contents)
Loads this
YamlConfiguration from the specified string. |
protected void |
loadHeader(Reader reader) |
YamlConfigurationOptions |
options()
Gets the
ConfigurationOptions for this Configuration . |
void |
save(Writer writer)
Save the configuration values including the header.
|
String |
saveToString()
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 |
setImplementation(YamlImplementation yamlImplementation) |
buildHeader, load, save, save
addDefault, addDefaults, addDefaults, getDefaults, getParent, setDefaults
contains, createPath, createPath, createSection, createSection, get, getBoolean, getBoolean, getBooleanList, getByteList, getCharacterList, getConfigurationSection, getCurrentPath, getDefault, getDefaultSection, getDouble, getDouble, getDoubleList, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getMapValues, getName, getRoot, getShortList, getString, getString, getStringList, getValues, isBoolean, isConfigurationSection, isDouble, isEmpty, isInt, isList, isLong, isPrimitiveWrapper, isSet, isString, mapChildrenKeys, mapChildrenValues, size, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, createSection, createSection, get, getBoolean, getBoolean, getBooleanList, getByteList, getCharacterList, getConfigurationSection, getCurrentPath, getDefaultSection, getDouble, getDouble, getDoubleList, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getMapValues, getName, getRoot, getShortList, getString, getString, getStringList, getValues, isBoolean, isConfigurationSection, isDouble, isEmpty, isInt, isList, isLong, isSet, isString, remove, size
protected YamlImplementation yamlImplementation
public YamlConfiguration()
YamlConfiguration
.public YamlConfiguration(Configuration defaults)
YamlConfiguration
using the specified
Configuration
as a source for all default values.defaults
- default valuespublic YamlConfiguration(YamlImplementation yamlImplementation)
public YamlConfiguration(Configuration defaults, YamlImplementation yamlImplementation)
public YamlImplementation getImplementation()
public void setImplementation(YamlImplementation yamlImplementation)
public String saveToString() throws IOException
IOException
- when the contents cannot be written for any reasonpublic void save(Writer writer) throws IOException
save
in interface LoadableConfiguration
save
in class FileConfiguration
writer
- where to save this configurationIOException
- when the contents cannot be written for any reasonsaveToString()
public String dump() throws IOException
IOException
- when the contents cannot be written for any reasonsaveToString()
public void dump(Writer writer) throws IOException
writer
- where to save this configurationIOException
- when the contents cannot be written for any reasonsave(Writer)
public void load(SupplierIO.Reader readerSupplier) throws IOException, InvalidConfigurationException
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.
readerSupplier
- a function providing the reader to load from (new instance)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.protected void loadHeader(Reader reader) throws IOException
IOException
public static YamlConfiguration loadConfiguration(SupplierIO.Reader readerSupplier) throws IOException
YamlConfiguration
, loading from the given reader.readerSupplier
- a function providing the reader to load from (new instance)IllegalArgumentException
- if stream is nullIOException
- if cannot load configurationpublic static YamlConfiguration loadConfiguration(File file) throws IOException
YamlConfiguration
, loading from the given file.
This method will use the options()
charset
encoding,
which defaults to UTF8.
file
- Input fileIllegalArgumentException
- if file is nullIOException
- if cannot load configurationpublic void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException
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.
load
in class FileConfiguration
file
- File to load from.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.public static YamlConfiguration loadConfigurationFromString(String contents) throws IOException
YamlConfiguration
, loading from the specified string contents.
If the file cannot be loaded for any reason, an exception will be thrown.
contents
- the contents to load fromIOException
- Thrown when underlying reader throws an IOException.InvalidConfigurationException
- Thrown when the contents does not represent a valid Configuration.IllegalArgumentException
- Thrown when contents is null.public void loadFromString(String contents) throws IOException
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.
contents
- the contents to load fromIOException
- Thrown when underlying reader throws an IOException.InvalidConfigurationException
- Thrown when the contents does not represent a valid Configuration.IllegalArgumentException
- Thrown when contents is null.public static YamlConfiguration loadConfiguration(SupplierIO.InputStream streamSupplier) throws IOException
YamlConfiguration
, loading from the given input stream.
If the file cannot be loaded for any reason, an exception will be thrown.
streamSupplier
- a function providing the stream to load from (new instance)InvalidConfigurationException
- if input stream is not a valid Configuration.IllegalArgumentException
- if stream is nullIOException
- if cannot load configurationpublic void load(SupplierIO.InputStream streamSupplier) throws IOException, InvalidConfigurationException
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.
streamSupplier
- a function providing the stream to load from (new instance)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.load(SupplierIO.Reader)
@Deprecated public static YamlConfiguration loadConfiguration(InputStream stream) throws IOException
load(SupplierIO.InputStream)
YamlConfiguration
, loading from the given stream.
This method will use the options()
charset
encoding,
which defaults to UTF8.
stream
- Input streamIllegalArgumentException
- if stream is nullIOException
- if cannot load configurationloadConfiguration(SupplierIO.InputStream)
,
loadConfiguration(SupplierIO.Reader)
@Deprecated public void load(InputStream stream) throws IOException, InvalidConfigurationException
load(SupplierIO.InputStream)
FileConfiguration
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()
charset
encoding,
which defaults to UTF8.
load
in class FileConfiguration
stream
- Stream to load fromIOException
- Thrown when the given file cannot be read.InvalidConfigurationException
- Thrown when the given file is not a valid Configuration.loadConfiguration(SupplierIO.InputStream)
@Deprecated public static YamlConfiguration loadConfiguration(Reader reader) throws IOException
load(SupplierIO.Reader)
YamlConfiguration
, loading from the given reader.reader
- input readerIllegalArgumentException
- if stream is nullIOException
- if cannot load configurationloadConfiguration(SupplierIO.Reader)
,
loadConfiguration(SupplierIO.InputStream)
@Deprecated public void load(Reader reader) throws IOException, InvalidConfigurationException
load(SupplierIO.Reader)
FileConfiguration
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.
load
in interface LoadableConfiguration
load
in class FileConfiguration
reader
- the reader to load fromIOException
- Thrown when underlying reader throws an IOException.InvalidConfigurationException
- Thrown when the reader does not represent a valid Configuration.loadConfiguration(SupplierIO.Reader)
public void set(String path, Object value, QuoteStyle quoteStyle)
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 store Configuration
s or ConfigurationSection
s,
please use MemorySection.createSection(String)
for that.path
- Path of the object to set.value
- New value to set the path to.quoteStyle
- The quote style to use.public void set(String path, Object 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 Configuration
s or ConfigurationSection
s,
please use MemorySection.createSection(String)
for that.
set
in interface ConfigurationSection
set
in class MemorySection
path
- Path of the object to set.value
- New value to set the path to.public Object get(String path, Object def)
ConfigurationSection
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
.
get
in interface ConfigurationSection
get
in class MemorySection
path
- Path of the Object to get.def
- The default value to return if the path is not found.public YamlConfigurationOptions options()
Configuration
ConfigurationOptions
for this Configuration
.
All setters through this method are chainable.
options
in interface Configuration
options
in class FileConfiguration
Copyright © 2023. All rights reserved.