Package net.sourceforge.jnlp.util
Class PropertiesFile
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,
Object>
A properties object backed by a specified file without throwing
exceptions. The properties are automatically loaded from the
file when the first property is requested, but the save method
must be called before changes are saved to the file.
- See Also:
-
Field Summary
Fields inherited from class java.util.Properties
defaults
-
Constructor Summary
ConstructorsConstructorDescriptionPropertiesFile
(File file) Create a properties object backed by the specified file.PropertiesFile
(File file, String header) Create a properties object backed by the specified file. -
Method Summary
Modifier and TypeMethodDescriptiongetProperty
(String key) getProperty
(String key, String defaultValue) boolean
boolean
load()
Ensures that the file backing these properties has been loaded; call this method before calling any method defined by a superclass.void
lock()
setProperty
(String key, String value) Sets the value for the specified key.void
store()
Saves the properties to the file.boolean
tryLock()
void
unlock()
Unlocks the file.Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
PropertiesFile
Create a properties object backed by the specified file.- Parameters:
file
- the file to save and load to
-
PropertiesFile
Create a properties object backed by the specified file.- Parameters:
file
- the file to save and load toheader
- the file header
-
-
Method Details
-
getProperty
- Overrides:
getProperty
in classProperties
- Returns:
- the value of the specified key, or null if the key does not exist.
-
getProperty
- Overrides:
getProperty
in classProperties
- Returns:
- the value of the specified key, or the default value if the key does not exist.
-
setProperty
Sets the value for the specified key.- Overrides:
setProperty
in classProperties
- Returns:
- the previous value
-
getStoreFile
- Returns:
- the file backing this properties object.
-
load
public boolean load()Ensures that the file backing these properties has been loaded; call this method before calling any method defined by a superclass.- Returns:
- true, if file was (re-)loaded false, if file was still current
-
store
public void store()Saves the properties to the file. -
lock
public void lock() -
tryLock
public boolean tryLock() -
unlock
public void unlock()Unlocks the file. Does not do anything if not holding the lock. -
isHeldByCurrentThread
public boolean isHeldByCurrentThread()
-