Class AbstractConfigurationLoader<N extends ScopedConfigurationNode<N>>
- Type Parameters:
N- theConfigurationNodetype 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 classAbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T,L>, L extends AbstractConfigurationLoader<?>> An abstract builder implementation forAbstractConfigurationLoaders. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternA pattern that will match line breaks in comments.static final StringThe 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 StringThe line separator used by the system. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConfigurationLoader(AbstractConfigurationLoader.Builder<?, ?> builder, CommentHandler[] commentHandlers) Create a loader instance from a builder. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancanLoad()Gets if this loader is capable of loading configurations.final booleancanSave()Gets if this loader is capable of saving configurations.protected voidPerform format-specific validation of a node.Gets the primaryCommentHandlerused by this loader.Default options for the types of nodes created by this factory.load(ConfigurationOptions options) Attempts to load aConfigurationNodeusing this loader, from the defined source.protected abstract voidloadInternal(N node, BufferedReader reader) Using a created node, attempt to read a configuration file.Attempts to load data from the defined source into aConfigurationReference.voidsave(ConfigurationNode node) Attempts to save aConfigurationNodeusing this loader, to the defined sink.protected abstract voidsaveInternal(ConfigurationNode node, Writer writer) Perform a save of the node to the provided writer.protected voidwriteHeaderInternal(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, waitMethods inherited from interface org.spongepowered.configurate.loader.ConfigurationLoader
loadMethods 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 primaryCommentHandlerused by this loader.- Returns:
- the default comment handler
- Since:
- 4.0.0
-
loadToReference
Description copied from interface:ConfigurationLoaderAttempts to load data from the defined source into aConfigurationReference. The returned reference will not reload automatically.- Specified by:
loadToReferencein 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:ConfigurationLoaderAttempts to load aConfigurationNodeusing this loader, from the defined source.The resultant node represents the root of the configuration being loaded.
- Specified by:
loadin 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:ConfigurationLoaderAttempts to save aConfigurationNodeusing this loader, to the defined sink.- Specified by:
savein 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:ConfigurationNodeFactoryDefault 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:
defaultOptionsin interfaceConfigurationNodeFactory<N extends ScopedConfigurationNode<N>>- Returns:
- default options
-
canLoad
Description copied from interface:ConfigurationLoaderGets if this loader is capable of loading configurations.- Specified by:
canLoadin interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>- Returns:
- if this loader can load
-
canSave
Description copied from interface:ConfigurationLoaderGets if this loader is capable of saving configurations.- Specified by:
canSavein interfaceConfigurationLoader<N extends ScopedConfigurationNode<N>>- Returns:
- if this loader can save
-