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
All Methods Instance Methods Abstract Methods Concrete Methods 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, 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
ASplitterfor 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 primaryCommentHandlerused by this loader.- Returns:
- The default comment handler
-
load
public @NonNull NodeType load(@NonNull ConfigurationOptions options) throws IOException
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
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: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
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: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
public final boolean 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
public final boolean 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
-
-