public class PropertiesFile
extends java.lang.Object
Constructor and Description |
---|
PropertiesFile(java.io.File file)
Constructor with file.
|
PropertiesFile(java.io.File file,
java.lang.String encoding)
Constructor with file and encoding.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Discards all properties in memory (not on disk!).
|
boolean |
delete()
Tries to delete the underlying file.
|
boolean |
exists()
Determines if the underlying file already exists.
|
java.lang.String |
get(java.lang.String key)
Returns a value for a given key.
|
java.lang.String |
getEncoding()
Returns the encoding of the file.
|
java.io.File |
getFile()
Returns the underlying file.
|
java.lang.String[] |
getKeyArray()
Returns an array of all known keys including the deleted ones.
|
java.util.List |
getKeyList()
Returns a list of all known keys including the deleted ones.
|
java.lang.String |
getStatus(java.lang.String key)
Returns a status text for a given key.
|
int |
getTryLockMax()
Returns the number of tries to lock before throwing an exception.
|
long |
getTryWaitMillis()
Returns the milliseconds to sleep between retries.
|
boolean |
isLoaded()
Returns if the underlying file has ever been read.
|
boolean |
isRemoved(java.lang.String key)
Returns if a property has been deleted.
|
java.util.Iterator |
keyIterator()
Returns a key iterator.
|
void |
load()
Loads or reloads the content of the underlying file.
|
void |
put(java.lang.String key,
java.lang.String value)
Set a value for a property.
|
void |
remove(java.lang.String key)
Remove the property with the given key.
|
void |
save(boolean sortByKey)
Save the content from memory to disk.
|
void |
save(java.lang.String[] comments,
boolean sortByKey)
Save the content from memory to disk.
|
void |
save(java.lang.String comment,
boolean sortByKey)
Save the content from memory to disk.
|
void |
setTryLockMax(int tryLockMax)
Sets the number of tries to lock before throwing an exception.
|
void |
setTryWaitMillis(long tryWaitMillis)
Sets the milliseconds to sleep between retries.
|
int |
size()
Number of properties.
|
java.util.Properties |
toProperties()
Returns a copy of all properties.
|
public PropertiesFile(java.io.File file)
file
- File reference.public PropertiesFile(java.io.File file, java.lang.String encoding)
file
- File reference.encoding
- File encoding ("UTF-8" etc.)public final java.lang.String getEncoding()
public final boolean isLoaded()
true
else false
.public final void clear()
public final void load() throws java.io.IOException, LockingFailedException, MergeException
clear()
before!java.io.IOException
- Error reading the file.LockingFailedException
- Locking the file failed.MergeException
- A problem occurred when merging the properties in memory and
from disk.public final void save(boolean sortByKey) throws java.io.IOException, MergeException, LockingFailedException
sortByKey
- Sort the properties by key before saving?java.io.IOException
- Error writing the file.MergeException
- One or more properties were modified concurrently.LockingFailedException
- Locking the file failed.public final void save(java.lang.String comment, boolean sortByKey) throws java.io.IOException, MergeException, LockingFailedException
comment
- Comment to prepend (Should not include the "#" comment sign -
It will be prepended automatically).sortByKey
- Sort the properties by key before saving?java.io.IOException
- Error writing the file.MergeException
- One or more properties were modified concurrently.LockingFailedException
- Locking the file failed.public final void save(java.lang.String[] comments, boolean sortByKey) throws java.io.IOException, MergeException, LockingFailedException
comments
- Comments to prepend (Should not include the "#" comment sign -
It will be prepended automatically).sortByKey
- Sort the properties by key before saving?java.io.IOException
- Error writing the file.MergeException
- One or more properties were modified concurrently.LockingFailedException
- Locking the file failed.public final java.lang.String get(java.lang.String key)
key
- Key to find.null
if the key is unknown.public final java.lang.String getStatus(java.lang.String key)
key
- Key to find.null
if the key is unknown.public final void put(java.lang.String key, java.lang.String value)
key
- Key to set.value
- Value to set.public final void remove(java.lang.String key)
null
and the
method isDeleted()
will return true
.key
- Key for the property to remove.public final boolean isRemoved(java.lang.String key)
key
- Key for the property to check.true
else false
.public final int size()
public final java.io.File getFile()
public final java.util.List getKeyList()
public final java.lang.String[] getKeyArray()
public final java.util.Iterator keyIterator()
public final java.util.Properties toProperties()
public final int getTryLockMax()
public final void setTryLockMax(int tryLockMax)
tryLockMax
- Number of tries (default=3).public final long getTryWaitMillis()
public final void setTryWaitMillis(long tryWaitMillis)
tryWaitMillis
- Milliseconds.public final boolean exists()
true
else false
public final boolean delete()
clear()
.true
else
false