Package ninja.leaping.configurate.loader
Class AbstractConfigurationLoader<NodeType extends ConfigurationNode>
java.lang.Object
ninja.leaping.configurate.loader.AbstractConfigurationLoader<NodeType>
- Type Parameters:
NodeType- TheConfigurationNodetype produced by the loader
- All Implemented Interfaces:
ConfigurationLoader<NodeType>
- Direct Known Subclasses:
GsonConfigurationLoader,HoconConfigurationLoader,JSONConfigurationLoader,XMLConfigurationLoader,YAMLConfigurationLoader
public abstract class AbstractConfigurationLoader<NodeType extends ConfigurationNode> extends Object implements ConfigurationLoader<NodeType>
Base class for many stream-based configuration loaders. This class provides conversion from a variety of input
sources to CharSource/Sink objects, 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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T>>An abstract builder implementation forAbstractConfigurationLoaders. -
Field Summary
Fields Modifier and Type Field Description static StringCONFIGURATE_LINE_SEPARATORThe escape sequence used by Configurate to separate comment linesprotected static SplitterLINE_SPLITTERASplitterfor splitting comment linesprotected @Nullable Callable<BufferedWriter>sinkThe writer sink for this loader.protected @Nullable Callable<BufferedReader>sourceThe reader source for this loader.protected static StringSYSTEM_LINE_SEPARATORThe line separator used by the system -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConfigurationLoader(@NonNull AbstractConfigurationLoader.Builder<?> builder, @NonNull CommentHandler[] commentHandlers) -
Method Summary
Modifier and Type Method Description booleancanLoad()Gets if this loader is capable of loading configurations.booleancanSave()Gets if this loader is capable of saving configurations.@NonNull CommentHandlergetDefaultCommentHandler()Gets the primaryCommentHandlerused by this loader.@NonNull ConfigurationOptionsgetDefaultOptions()Gets the defaultConfigurationOptionsused by the loader.@NonNull NodeTypeload(@NonNull ConfigurationOptions options)Attempts to load aConfigurationNodeusing this loader, from the defined source.protected abstract voidloadInternal(NodeType node, BufferedReader reader)voidsave(@NonNull ConfigurationNode node)Attempts to save aConfigurationNodeusing this loader, to the defined sink.protected abstract voidsaveInternal(ConfigurationNode node, Writer writer)protected voidwriteHeaderInternal(Writer writer)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ninja.leaping.configurate.loader.ConfigurationLoader
createEmptyNode, createEmptyNode, load, loadToReference
-
Field Details
-
CONFIGURATE_LINE_SEPARATOR
The escape sequence used by Configurate to separate comment lines- See Also:
- Constant Field Values
-
LINE_SPLITTER
ASplitterfor splitting comment lines -
SYSTEM_LINE_SEPARATOR
The line separator used by the system- See Also:
System.lineSeparator()
-
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(@NonNull AbstractConfigurationLoader.Builder<?> builder, @NonNull CommentHandler[] commentHandlers)
-
-
Method Details
-
getDefaultCommentHandler
Gets the primaryCommentHandlerused by this loader.- Returns:
- The default comment handler
-
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<NodeType extends ConfigurationNode>- Parameters:
options- The options to load with- Returns:
- The newly constructed node
- Throws:
IOException- if any sort of error occurs with reading or parsing the configuration
-
loadInternal
- Throws:
IOException
-
save
Description copied from interface:ConfigurationLoaderAttempts to save aConfigurationNodeusing this loader, to the defined sink.- Specified by:
savein interfaceConfigurationLoader<NodeType extends ConfigurationNode>- Parameters:
node- The node to save- Throws:
IOException- if any sort of error occurs with writing or generating the configuration
-
writeHeaderInternal
- Throws:
IOException
-
saveInternal
- Throws:
IOException
-
getDefaultOptions
Description copied from interface:ConfigurationLoaderGets the defaultConfigurationOptionsused by the loader.New nodes will be created using the default options if a specific set is not defined.
- Specified by:
getDefaultOptionsin interfaceConfigurationLoader<NodeType extends ConfigurationNode>- Returns:
- The default options
-
canLoad
Description copied from interface:ConfigurationLoaderGets if this loader is capable of loading configurations.- Specified by:
canLoadin interfaceConfigurationLoader<NodeType extends ConfigurationNode>- Returns:
- If this loader can load
-
canSave
Description copied from interface:ConfigurationLoaderGets if this loader is capable of saving configurations.- Specified by:
canSavein interfaceConfigurationLoader<NodeType extends ConfigurationNode>- Returns:
- If this loader can save
-