Class GenericBuilder<Base extends Config,Result extends FileConfig>
java.lang.Object
com.electronwill.nightconfig.core.file.GenericBuilder<Base,Result>
- Direct Known Subclasses:
CommentedFileConfigBuilder,FileConfigBuilder
A generic FileConfig/CommentedFileConfig/someOtherFileConfig builder. The default settings are:
- Charset: UTF-8 - change it with
charset(Charset) - WritingMode: REPLACE - change it with
writingMode(WritingMode) - ParsingMode: REPLACE - change it with
parsingMode(ParsingMode) - FileNotFoundAction: CREATE_EMPTY - change it with
onFileNotFound(FileNotFoundAction) - Asynchronous writing, ie config.save() returns quickly and operates in the background -
change it with
sync() - Not autosaved - change it with
autosave() - Not autoreloaded - change it with
autoreload() - Not thread-safe - change it with
concurrent() - Values' insertion order preserved if
Config.isInsertionOrderPreserved()returns true when the builder is constructed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected Charsetprotected booleanprotected final Pathprotected final ConfigFormat<? extends Base>protected booleanprotected FileNotFoundActionprotected final ConfigParser<? extends Base>protected ParsingModeprotected booleanprotected final ConfigWriterprotected WritingMode -
Method Summary
Modifier and TypeMethodDescriptionMakes the configuration "autoreloaded", that is, itsFileConfig.load()method is automatically called when the file is modified.autosave()Makes the configuration "autosaved", that is, itsFileConfig.save()method is automatically called when it is modified.Uses a specific Supplier to create the backing maps (one for the top level and one for each sub-configuration) of the configuration.build()Creates a new FileConfig with the chosen settings.protected abstract ResultbuildAutosave(FileConfig chain) protected abstract ResultbuildNormal(FileConfig chain) Sets the charset used forFileConfig.save()andFileConfig.load().Makes the configuration concurrent, that is, thread-safe.defaultData(File file) Sets the file to copy when the config's file is not found.defaultData(URL url) Sets the URL of the data to copy when the config's file is not found.defaultData(Path file) Sets the file to copy when the config's file is not found.defaultResource(String resourcePath) Sets the resource (in the jar) to copy when the config's file is not found.protected final BaseonFileNotFound(FileNotFoundAction nefAction) Sets the action to execute when the config's file is not found.parsingMode(ParsingMode parsingMode) Sets the ParsingMode used forFileConfig.load()Makes the configuration preserve the insertion order of its values.sync()Makes the configuration "write-synchronized", that is, itsFileConfig.save()method blocks until the write operation completes.writingMode(WritingMode writingMode) Sets the WritingMode used forFileConfig.save()
-
Field Details
-
file
-
format
-
writer
-
parser
-
charset
-
writingMode
-
parsingMode
-
nefAction
-
sync
protected boolean sync -
autosave
protected boolean autosave -
autoreload
protected boolean autoreload -
concurrent
protected boolean concurrent -
insertionOrder
protected boolean insertionOrder -
mapCreator
-
-
Method Details
-
charset
Sets the charset used forFileConfig.save()andFileConfig.load().- Returns:
- this builder
-
writingMode
Sets the WritingMode used forFileConfig.save()- Returns:
- this builder
-
parsingMode
Sets the ParsingMode used forFileConfig.load()- Returns:
- this builder
-
onFileNotFound
Sets the action to execute when the config's file is not found.- Returns:
- this builder
-
defaultResource
Sets the resource (in the jar) to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyResource(resourcePath))- Parameters:
resourcePath- the resource's path- Returns:
- this builder
-
defaultData
Sets the file to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyData(file))- Parameters:
file- the data file- Returns:
- this builder
-
defaultData
Sets the file to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyData(file))- Parameters:
file- the data file- Returns:
- this builder
-
defaultData
Sets the URL of the data to copy when the config's file is not found. This is a shortcut foronFileNotFound(FileNotFoundAction.copyData(url))- Parameters:
url- the data url- Returns:
- this builder
-
sync
Makes the configuration "write-synchronized", that is, itsFileConfig.save()method blocks until the write operation completes.- Returns:
- this builder
-
autosave
Makes the configuration "autosaved", that is, itsFileConfig.save()method is automatically called when it is modified.- Returns:
- this builder
-
autoreload
Makes the configuration "autoreloaded", that is, itsFileConfig.load()method is automatically called when the file is modified.- Returns:
- this builder
-
concurrent
Makes the configuration concurrent, that is, thread-safe.- Returns:
- this builder
-
preserveInsertionOrder
Makes the configuration preserve the insertion order of its values.- Returns:
- this builder
-
backingMapCreator
Uses a specific Supplier to create the backing maps (one for the top level and one for each sub-configuration) of the configuration.
Warning : ifautoreload()is called, the map creator must return thread-safe maps, because the autoreloading system will modify the configuration from another thread.- Parameters:
s- the map supplier to use- Returns:
- this builder
-
build
Creates a new FileConfig with the chosen settings.- Returns:
- the config
-
buildAutosave
-
buildNormal
-
getConfig
-