Class AbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T,L>,L extends AbstractConfigurationLoader<?>>
- java.lang.Object
-
- org.spongepowered.configurate.loader.AbstractConfigurationLoader.Builder<T,L>
-
- Type Parameters:
T
- the builder's own type (for chaining using generic types)
- Enclosing class:
- AbstractConfigurationLoader<N extends ScopedConfigurationNode<N>>
public abstract static class AbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T,L>,L extends AbstractConfigurationLoader<?>> extends java.lang.Object
An abstract builder implementation forAbstractConfigurationLoader
s.- Since:
- 4.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected static LoaderOptionSource
DEFAULT_OPTIONS_SOURCE
protected ConfigurationOptions
defaultOptions
protected HeaderMode
headerMode
protected @Nullable java.util.concurrent.Callable<java.io.BufferedWriter>
sink
protected @Nullable java.util.concurrent.Callable<java.io.BufferedReader>
source
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
Create a new builder.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract L
build()
Builds the loader.ConfigurationNode
buildAndLoadString(java.lang.String input)
Configure to read from a string, build, and load in one step.java.lang.String
buildAndSaveString(ConfigurationNode output)
Configure to write to a string, build, and save in one step.ConfigurationOptions
defaultOptions()
Gets the default configuration options to be used by the resultant loader.T
defaultOptions(java.util.function.UnaryOperator<ConfigurationOptions> defaultOptions)
Sets the default configuration options to be used by the resultant loader by providing a function which takes the current default options and applies any desired changes.T
defaultOptions(ConfigurationOptions defaultOptions)
Sets the default configuration options to be used by the resultant loader.T
file(java.io.File file)
Sets the sink and source of the resultant loader to the given file.T
from(LoaderOptionSource source)
Populate this builder by reading options from the provided source.HeaderMode
headerMode()
Gets the header mode to be used by the resultant loader.T
headerMode(HeaderMode mode)
Sets the header mode of the resultant loader.T
path(java.nio.file.Path path)
Sets the sink and source of the resultant loader to the given path.protected void
populate(LoaderOptionSource options)
Populate options from the provided source.@Nullable java.util.concurrent.Callable<java.io.BufferedWriter>
sink()
Gets the sink to be used by the resultant loader.T
sink(@Nullable java.util.concurrent.Callable<java.io.BufferedWriter> sink)
Sets the sink of the resultant loader.@Nullable java.util.concurrent.Callable<java.io.BufferedReader>
source()
Gets the source to be used by the resultant loader.T
source(@Nullable java.util.concurrent.Callable<java.io.BufferedReader> source)
Sets the source of the resultant loader.T
url(java.net.URL url)
Sets the source of the resultant loader to the given URL.
-
-
-
Field Detail
-
DEFAULT_OPTIONS_SOURCE
protected static final LoaderOptionSource DEFAULT_OPTIONS_SOURCE
-
headerMode
protected HeaderMode headerMode
-
source
protected @Nullable java.util.concurrent.Callable<java.io.BufferedReader> source
-
sink
protected @Nullable java.util.concurrent.Callable<java.io.BufferedWriter> sink
-
defaultOptions
protected ConfigurationOptions defaultOptions
-
-
Constructor Detail
-
Builder
protected Builder()
Create a new builder.This is where any custom default options can be applied.
At the end of this constructor,
from(LoaderOptionSource)
should be called withDEFAULT_OPTIONS_SOURCE
to read any supported options from environment variables and system properties.- Since:
- 4.0.0
-
-
Method Detail
-
from
public final T from(LoaderOptionSource source)
Populate this builder by reading options from the provided source.These options should control all options for the reading and representation of nodes produced by this loader, specifically excluding the
source()
andsink()
of the loader, and thedefaultOptions()
.The options read from the provided source are format-defined.
- Parameters:
source
- the source to read- Returns:
- this builder (for chaining)
- Since:
- 4.2.0
-
populate
@ForOverride protected void populate(LoaderOptionSource options)
Populate options from the provided source.The source will have already been validated for nullness.
- Parameters:
options
- the options to read- Since:
- 4.2.0
-
file
public T file(java.io.File file)
Sets the sink and source of the resultant loader to the given file.The
source
is defined usingFiles.newBufferedReader(Path)
with UTF-8 encoding.The
sink
is defined usingAtomicFiles
with UTF-8 encoding.- Parameters:
file
- the configuration file- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
path
public T path(java.nio.file.Path path)
Sets the sink and source of the resultant loader to the given path.The
source
is defined usingFiles.newBufferedReader(Path)
with UTF-8 encoding.The
sink
is defined usingAtomicFiles
with UTF-8 encoding.- Parameters:
path
- the path of the configuration file- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
url
public T url(java.net.URL url)
Sets the source of the resultant loader to the given URL.- Parameters:
url
- the URL of the source- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
source
public T source(@Nullable java.util.concurrent.Callable<java.io.BufferedReader> source)
Sets the source of the resultant loader.The "source" is used by the loader to load the configuration.
- Parameters:
source
- the source- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
source
public @Nullable java.util.concurrent.Callable<java.io.BufferedReader> source()
Gets the source to be used by the resultant loader.- Returns:
- the source
- Since:
- 4.0.0
-
sink
public T sink(@Nullable java.util.concurrent.Callable<java.io.BufferedWriter> sink)
Sets the sink of the resultant loader.The "sink" is used by the loader to save the configuration.
- Parameters:
sink
- the sink- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
sink
public @Nullable java.util.concurrent.Callable<java.io.BufferedWriter> sink()
Gets the sink to be used by the resultant loader.- Returns:
- the sink
- Since:
- 4.0.0
-
headerMode
public T headerMode(HeaderMode mode)
Sets the header mode of the resultant loader.- Parameters:
mode
- the header mode- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
headerMode
public HeaderMode headerMode()
Gets the header mode to be used by the resultant loader.- Returns:
- the header mode
- Since:
- 4.0.0
-
defaultOptions
public T defaultOptions(ConfigurationOptions defaultOptions)
Sets the default configuration options to be used by the resultant loader.- Parameters:
defaultOptions
- the options- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
defaultOptions
public T defaultOptions(java.util.function.UnaryOperator<ConfigurationOptions> defaultOptions)
Sets the default configuration options to be used by the resultant loader by providing a function which takes the current default options and applies any desired changes.- Parameters:
defaultOptions
- to transform the existing default options- Returns:
- this builder (for chaining)
- Since:
- 4.0.0
-
defaultOptions
public ConfigurationOptions defaultOptions()
Gets the default configuration options to be used by the resultant loader.- Returns:
- the options
- Since:
- 4.0.0
-
buildAndLoadString
public ConfigurationNode buildAndLoadString(java.lang.String input) throws ConfigurateException
Configure to read from a string, build, and load in one step.- Parameters:
input
- the input to load- Returns:
- a deserialized node
- Throws:
ConfigurateException
- Since:
- 4.1.0
-
buildAndSaveString
public java.lang.String buildAndSaveString(ConfigurationNode output) throws ConfigurateException
Configure to write to a string, build, and save in one step.- Parameters:
output
- the node to write- Returns:
- the output string
- Throws:
ConfigurateException
- Since:
- 4.1.0
-
-