Class AbstractConfigurationLoader<N extends ScopedConfigurationNode<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
BufferedReader
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 ClassesModifier and TypeClassDescriptionstatic class
AbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T,
L>, L extends AbstractConfigurationLoader<?>> An abstract builder implementation forAbstractConfigurationLoader
s. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Pattern
A pattern that will match line breaks in comments.static final String
The escape sequence used by Configurate to separate comment lines.protected final @Nullable Callable<BufferedWriter>
The writer sink for this loader.protected final @Nullable Callable<BufferedReader>
The reader source for this loader.protected static final String
The line separator used by the system. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractConfigurationLoader
(AbstractConfigurationLoader.Builder<?, ?> builder, CommentHandler[] commentHandlers) Create a loader instance from a builder. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
canLoad()
Gets if this loader is capable of loading configurations.final boolean
canSave()
Gets if this loader is capable of saving configurations.protected void
Perform format-specific validation of a node.Gets the primaryCommentHandler
used by this loader.Default options for the types of nodes created by this factory.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.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 Details
-
CONFIGURATE_LINE_SEPARATOR
The escape sequence used by Configurate to separate comment lines.- See Also:
-
CONFIGURATE_LINE_PATTERN
A pattern that will match line breaks in comments. -
SYSTEM_LINE_SEPARATOR
The line separator used by the system.- See Also:
-
source
The reader source for this loader.Can be null (for loaders which don't support loading!)
-
sink
The writer sink for this loader.Can be null (for loaders which don't support saving!)
-
-
Constructor Details
-
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 Details
-
defaultCommentHandler
Gets the primaryCommentHandler
used by this loader.- Returns:
- the default comment handler
- Since:
- 4.0.0
-
loadToReference
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:
-
load
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
@ForOverride 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
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
-
checkCanWrite
Perform format-specific validation of a node.This method will be called before a writer is opened, allowing the loader to perform any basic validation it may need to before it opens a writer replacing an existing file.
- Parameters:
node
- the node to write- Throws:
ConfigurateException
- if any invalid data is present- Since:
- 4.1.0
-
writeHeaderInternal
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
@ForOverride 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
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
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
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
-