public class FileBasedConfig extends StoredConfig
Config.ConfigEnum, Config.SectionParser<T>| Modifier and Type | Field and Description |
|---|---|
private java.io.File |
configFile |
private FS |
fs |
private ObjectId |
hash |
private FileSnapshot |
snapshot |
private boolean |
utf8Bom |
| Constructor and Description |
|---|
FileBasedConfig(Config base,
java.io.File cfgLocation,
FS fs)
The constructor
|
FileBasedConfig(java.io.File cfgLocation,
FS fs)
Create a configuration with no default fallback.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the configuration file
|
java.io.File |
getFile()
Get location of the configuration file on disk
|
private static ObjectId |
hash(byte[] rawText) |
boolean |
isOutdated()
Whether the currently loaded configuration file is outdated
|
void |
load()
Load the configuration from the persistent store.
|
protected boolean |
notifyUponTransientChanges()
Determine whether to issue change events for transient changes.
|
protected byte[] |
readIncludedConfig(java.lang.String relPath)
Read the included config from the specified (possibly) relative path
|
void |
save()
Save the configuration to the persistent store.
|
java.lang.String |
toString() |
addChangeListener, fireConfigChangedEvent, fromText, get, getBoolean, getBoolean, getEnum, getEnum, getInt, getInt, getLong, getLong, getNames, getNames, getNames, getNames, getRefSpecs, getSections, getString, getStringList, getSubsections, getTimeUnit, isUtf8, setBoolean, setEnum, setInt, setLong, setString, setStringList, setTypedConfigGetter, toText, uncache, unset, unsetSectionprivate final java.io.File configFile
private final FS fs
private boolean utf8Bom
private volatile FileSnapshot snapshot
private volatile ObjectId hash
public FileBasedConfig(java.io.File cfgLocation,
FS fs)
cfgLocation - the location of the configuration file on the file systemfs - the file system abstraction which will be necessary to perform
certain file system operations.public FileBasedConfig(Config base, java.io.File cfgLocation, FS fs)
base - the base configuration filecfgLocation - the location of the configuration file on the file systemfs - the file system abstraction which will be necessary to perform
certain file system operations.protected boolean notifyUponTransientChanges()
If true is returned (which is the default behavior),
Config.fireConfigChangedEvent() will be called upon each change.
Subclasses that override this to return false are
responsible for issuing Config.fireConfigChangedEvent() calls
themselves.
notifyUponTransientChanges in class Configpublic final java.io.File getFile()
public void load()
throws java.io.IOException,
ConfigInvalidException
If the configuration does not exist, this configuration is cleared, and thus behaves the same as though the backing store exists, but is empty.
Load the configuration as a Git text style configuration file.
If the file does not exist, this configuration is cleared, and thus behaves the same as though the file exists, but is empty.
load in class StoredConfigjava.io.IOException - the configuration could not be read (but does exist).ConfigInvalidException - the configuration is not properly formatted.public void save()
throws java.io.IOException
Save the configuration as a Git text style configuration file.
Warning: Although this method uses the traditional Git file locking approach to protect against concurrent writes of the configuration file, it does not ensure that the file has not been modified since the last read, which means updates performed by other objects accessing the same backing file may be lost.
save in class StoredConfigjava.io.IOException - the configuration could not be written.public void clear()
clear in class StoredConfigprivate static ObjectId hash(byte[] rawText)
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isOutdated()
@Nullable protected byte[] readIncludedConfig(java.lang.String relPath) throws ConfigInvalidException
readIncludedConfig in class ConfigrelPath - possibly relative path to the included config, as specified in
this configConfigInvalidException - if something went wrong while reading the config