netx.jnlp.util

Class PropertiesFile


public class PropertiesFile
extends Properties

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.

This class does not report IO exceptions.

Version:
$Revision: 1.4 $
Author:
Jon A. Maxwell (JAM) - initial author

Field Summary

(package private) File
file
the file to save to
(package private) String
header
the header string
(package private) boolean
loaded
lazy loaded on getProperty

Constructor Summary

PropertiesFile(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

String
getProperty(String key)
Returns the value of the specified key, or null if the key does not exist.
String
getProperty(String key, String defaultValue)
Returns the value of the specified key, or the default value if the key does not exist.
File
getStoreFile()
Returns the file backing this properties object.
void
load()
Ensures that the file backing these properties has been loaded; call this method before calling any method defined by a superclass.
Object
setProperty(String key, String value)
Sets the value for the specified key.
void
store()
Saves the properties to the file.

Field Details

file

(package private)  File file
the file to save to

header

(package private)  String header
the header string

loaded

(package private)  boolean loaded
lazy loaded on getProperty

Constructor Details

PropertiesFile

public PropertiesFile(File file)
Create a properties object backed by the specified file.
Parameters:
file - the file to save and load to

PropertiesFile

public PropertiesFile(File file,
                      String header)
Create a properties object backed by the specified file.
Parameters:
file - the file to save and load to
header - the file header

Method Details

getProperty

public String getProperty(String key)
Returns the value of the specified key, or null if the key does not exist.

getProperty

public String getProperty(String key,
                          String defaultValue)
Returns the value of the specified key, or the default value if the key does not exist.

getStoreFile

public File getStoreFile()
Returns the file backing this properties object.

load

public void load()
Ensures that the file backing these properties has been loaded; call this method before calling any method defined by a superclass.

setProperty

public Object setProperty(String key,
                          String value)
Sets the value for the specified key.
Returns:
the previous value

store

public void store()
Saves the properties to the file.