Class AbstractConfigurationLoader<N extends ScopedConfigurationNode<N>>
- java.lang.Object
-
- org.spongepowered.configurate.loader.AbstractConfigurationLoader<N>
-
- Type Parameters:
N
- theConfigurationNode
type produced by the loader
- All Implemented Interfaces:
ConfigurationNodeFactory<N>
,ConfigurationLoader<N>
- Direct Known Subclasses:
GsonConfigurationLoader
,HoconConfigurationLoader
,JacksonConfigurationLoader
,XmlConfigurationLoader
,YamlConfigurationLoader
public abstract class AbstractConfigurationLoader<N extends ScopedConfigurationNode<N>> extends Object implements ConfigurationLoader<N>
Base class for many stream-based configuration loaders. This class provides conversion from a variety of input sources toBufferedReader
suppliers, providing a consistent API for loaders to read from and write to.Either the source or sink may be null. If this is true, this loader may not support either loading or saving. In this case, implementing classes are expected to throw an
IOException
for the unsupported operation.- Since:
- 4.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T,L>,L extends AbstractConfigurationLoader<?>>
An abstract builder implementation forAbstractConfigurationLoader
s.
-
Field Summary
Fields Modifier and Type Field Description static Pattern
CONFIGURATE_LINE_PATTERN
A pattern that will match line breaks in comments.static String
CONFIGURATE_LINE_SEPARATOR
The escape sequence used by Configurate to separate comment lines.protected @Nullable Callable<BufferedWriter>
sink
The writer sink for this loader.protected @Nullable Callable<BufferedReader>
source
The reader source for this loader.protected static String
SYSTEM_LINE_SEPARATOR
The line separator used by the system.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConfigurationLoader(AbstractConfigurationLoader.Builder<?,?> builder, CommentHandler[] commentHandlers)
Create a loader instance from a builder.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canLoad()
Gets if this loader is capable of loading configurations.boolean
canSave()
Gets if this loader is capable of saving configurations.CommentHandler
defaultCommentHandler()
Gets the primaryCommentHandler
used by this loader.ConfigurationOptions
defaultOptions()
Default options for the types of nodes created by this factory.N
load(ConfigurationOptions options)
Attempts to load aConfigurationNode
using this loader, from the defined source.protected abstract void
loadInternal(N node, BufferedReader reader)
Using a created node, attempt to read a configuration file.ConfigurationReference<N>
loadToReference()
Attempts to load data from the defined source into aConfigurationReference
.void
save(ConfigurationNode node)
Attempts to save aConfigurationNode
using this loader, to the defined sink.protected abstract void
saveInternal(ConfigurationNode node, Writer writer)
Perform a save of the node to the provided writer.protected void
writeHeaderInternal(Writer writer)
Write out any implementation-specific file header.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.spongepowered.configurate.loader.ConfigurationLoader
load
-
Methods inherited from interface org.spongepowered.configurate.ConfigurationNodeFactory
createNode, createNode, createNode, createNode, toListCollector, toListCollector, toMapCollector, toMapCollector
-
-
-
-
Field Detail
-
CONFIGURATE_LINE_SEPARATOR
public static final String CONFIGURATE_LINE_SEPARATOR
The escape sequence used by Configurate to separate comment lines.- See Also:
- Constant Field Values
-
CONFIGURATE_LINE_PATTERN
public static final Pattern CONFIGURATE_LINE_PATTERN
A pattern that will match line breaks in comments.
-
SYSTEM_LINE_SEPARATOR
protected static final String SYSTEM_LINE_SEPARATOR
The line separator used by the system.- See Also:
System.lineSeparator()
-
source
protected final @Nullable Callable<BufferedReader> source
The reader source for this loader.Can be null (for loaders which don't support loading!)
-
sink
protected final @Nullable Callable<BufferedWriter> sink
The writer sink for this loader.Can be null (for loaders which don't support saving!)
-
-
Constructor Detail
-
AbstractConfigurationLoader
protected AbstractConfigurationLoader(AbstractConfigurationLoader.Builder<?,?> builder, CommentHandler[] commentHandlers)
Create a loader instance from a builder.- Parameters:
builder
- the user-configured buildercommentHandlers
- supported comment formats for extracting the configuration header- Since:
- 4.0.0
-
-
Method Detail
-
defaultCommentHandler
public CommentHandler defaultCommentHandler()
Gets the primaryCommentHandler
used by this loader.- Returns:
- the default comment handler
- Since:
- 4.0.0
-
loadToReference
public ConfigurationReference<N> loadToReference() throws ConfigurateException
Description copied from interface:ConfigurationLoader
Attempts to load data from the defined source into aConfigurationReference
. The returned reference will not reload automatically.- Specified by:
loadToReference
in interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>
- Returns:
- the created reference
- Throws:
ConfigurateException
- when an error occurs within the loader- See Also:
to create an auto-reloading configuration.
-
load
public N load(ConfigurationOptions options) throws ParsingException
Description copied from interface:ConfigurationLoader
Attempts to load aConfigurationNode
using this loader, from the defined source.The resultant node represents the root of the configuration being loaded.
- Specified by:
load
in interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>
- Parameters:
options
- the options to load with- Returns:
- the newly constructed node
- Throws:
ParsingException
-
loadInternal
protected abstract void loadInternal(N node, BufferedReader reader) throws ParsingException
Using a created node, attempt to read a configuration file.The header will already have been read if applicable.
- Parameters:
node
- node to load intoreader
- reader to load from- Throws:
ParsingException
- if an error occurs at any stage of loading- Since:
- 4.0.0
-
save
public void save(ConfigurationNode node) throws ConfigurateException
Description copied from interface:ConfigurationLoader
Attempts to save aConfigurationNode
using this loader, to the defined sink.- Specified by:
save
in interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>
- Parameters:
node
- the node to save- Throws:
ConfigurateException
- if any sort of error occurs with writing or generating the configuration
-
writeHeaderInternal
protected void writeHeaderInternal(Writer writer) throws IOException
Write out any implementation-specific file header.- Parameters:
writer
- writer to output to- Throws:
IOException
- if an error occurs in the implementation- Since:
- 4.0.0
-
saveInternal
protected abstract void saveInternal(ConfigurationNode node, Writer writer) throws ConfigurateException
Perform a save of the node to the provided writer.- Parameters:
node
- node to savewriter
- writer to output to- Throws:
ConfigurateException
- if any of the node's data is unsavable- Since:
- 4.0.0
-
defaultOptions
public ConfigurationOptions defaultOptions()
Description copied from interface:ConfigurationNodeFactory
Default options for the types of nodes created by this factory.All values must match what a created node will see, but some values may be determined by this factory to be non user-modifiable. These should be documented for any factory implementation.
- Specified by:
defaultOptions
in interfaceConfigurationNodeFactory<N extends ScopedConfigurationNode<N>>
- Returns:
- default options
-
canLoad
public final boolean canLoad()
Description copied from interface:ConfigurationLoader
Gets if this loader is capable of loading configurations.- Specified by:
canLoad
in interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>
- Returns:
- if this loader can load
-
canSave
public final boolean canSave()
Description copied from interface:ConfigurationLoader
Gets if this loader is capable of saving configurations.- Specified by:
canSave
in interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>
- Returns:
- if this loader can save
-
-