Package ninja.leaping.configurate.loader
Class AbstractConfigurationLoader<NodeType extends ConfigurationNode>
- java.lang.Object
-
- ninja.leaping.configurate.loader.AbstractConfigurationLoader<NodeType>
-
- Type Parameters:
NodeType
- TheConfigurationNode
type 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 class
AbstractConfigurationLoader.Builder<T extends AbstractConfigurationLoader.Builder<T>>
An abstract builder implementation forAbstractConfigurationLoader
s.
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIGURATE_LINE_SEPARATOR
The escape sequence used by Configurate to separate comment linesprotected static Splitter
LINE_SPLITTER
ASplitter
for splitting comment linesprotected @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(@NonNull AbstractConfigurationLoader.Builder<?> builder, @NonNull CommentHandler[] commentHandlers)
-
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.@NonNull CommentHandler
getDefaultCommentHandler()
Gets the primaryCommentHandler
used by this loader.@NonNull ConfigurationOptions
getDefaultOptions()
Gets the defaultConfigurationOptions
used by the loader.@NonNull NodeType
load(@NonNull ConfigurationOptions options)
Attempts to load aConfigurationNode
using this loader, from the defined source.protected abstract void
loadInternal(NodeType node, BufferedReader reader)
void
save(@NonNull ConfigurationNode node)
Attempts to save aConfigurationNode
using this loader, to the defined sink.protected abstract void
saveInternal(ConfigurationNode node, Writer writer)
protected void
writeHeaderInternal(Writer writer)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ninja.leaping.configurate.loader.ConfigurationLoader
createEmptyNode, createEmptyNode, load, loadToReference
-
-
-
-
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
-
LINE_SPLITTER
protected static final Splitter LINE_SPLITTER
ASplitter
for splitting comment lines
-
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(@NonNull AbstractConfigurationLoader.Builder<?> builder, @NonNull CommentHandler[] commentHandlers)
-
-
Method Detail
-
getDefaultCommentHandler
public @NonNull CommentHandler getDefaultCommentHandler()
Gets the primaryCommentHandler
used by this loader.- Returns:
- The default comment handler
-
load
public @NonNull NodeType load(@NonNull ConfigurationOptions options) throws IOException
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<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
protected abstract void loadInternal(NodeType node, BufferedReader reader) throws IOException
- Throws:
IOException
-
save
public void save(@NonNull ConfigurationNode node) throws IOException
Description copied from interface:ConfigurationLoader
Attempts to save aConfigurationNode
using this loader, to the defined sink.- Specified by:
save
in 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
protected void writeHeaderInternal(Writer writer) throws IOException
- Throws:
IOException
-
saveInternal
protected abstract void saveInternal(ConfigurationNode node, Writer writer) throws IOException
- Throws:
IOException
-
getDefaultOptions
public @NonNull ConfigurationOptions getDefaultOptions()
Description copied from interface:ConfigurationLoader
Gets the defaultConfigurationOptions
used by the loader.New nodes will be created using the default options if a specific set is not defined.
- Specified by:
getDefaultOptions
in interfaceConfigurationLoader<NodeType extends ConfigurationNode>
- Returns:
- The 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<NodeType extends ConfigurationNode>
- 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<NodeType extends ConfigurationNode>
- Returns:
- If this loader can save
-
-