Package org.dlese.dpc.propertiesmgr
Class PropertiesManager
java.lang.Object
java.util.Dictionary<Object,Object>
java.util.Hashtable<Object,Object>
java.util.Properties
org.dlese.dpc.propertiesmgr.PropertiesManager
- All Implemented Interfaces:
Serializable,Cloneable,Map<Object,Object>
Reads and writes Java properties files. Properties files can be on disc or contained within a Jar file.
- Version:
- $Id: PropertiesManager.java,v 1.6 2009/03/20 23:33:54 jweather Exp $
- Author:
- John Weatherley
- See Also:
-
Field Summary
Fields inherited from class java.util.Properties
defaults -
Constructor Summary
ConstructorsConstructorDescriptionCreate an unloaded Properties object.PropertiesManager(String propsFileName) Create and load this Properties hash map from the given Properties file or properties resource located in the jar. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the property value from this object's property file.booleangetPropAsBoolean(String property, String defaultValue) Same as thegetProp(String,String)method only it returns it's parameter as a boolean.intgetPropAsInt(String property, String defaultValue) Same as thegetProp(String,String)method only it returns it's parameter as an integer.voidLoads or re-loads the properties from its file or JAR, replacing all previously loaded properties, if any.voidWrites the properties to the same file that was used to read them, preserving any comments in the file.voidwritePropsFile(String propsFilePath) Writes the properties to the given file path.Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
PropertiesManager
public PropertiesManager()Create an unloaded Properties object. Same as Properties(). -
PropertiesManager
Create and load this Properties hash map from the given Properties file or properties resource located in the jar.- Parameters:
propsFileName- The name of the Properties file to load or URL to the properties location inside a jar- Throws:
IOException- If unable to load the properties.
-
-
Method Details
-
loadPropertiesFile
Loads or re-loads the properties from its file or JAR, replacing all previously loaded properties, if any. If the file or JAR is not configured, does nothing.- Throws:
IOException- If error
-
writePropsFile
Writes the properties to the same file that was used to read them, preserving any comments in the file. If the original file was contained in a jar then an I/O excetion is thrown.- Throws:
IOException- If error in input/output
-
writePropsFile
Writes the properties to the given file path. If the file path is the same as the one used to upen this file, then all comments in the file are preserved.- Parameters:
propsFilePath- The full path to the props file to be written.- Throws:
IOException- If error in input/output
-
getProp
Retrieves the property value from this object's property file. If the property does not exist and a default value is specified, the default is set in the Properties and is returned.- Parameters:
property- The property sting to retrievedefaultValue- The default value for this property, if none is found- Returns:
- The prop value
- Throws:
Exception- If error
-
getPropAsInt
Same as thegetProp(String,String)method only it returns it's parameter as an integer.- Parameters:
property- The property sting to retrievedefaultValue- The default value for this property, if none is found- Returns:
- The prop value
- Throws:
Exception- If error
-
getPropAsBoolean
Same as thegetProp(String,String)method only it returns it's parameter as a boolean. Possible inputs are [yes|no|true|false|on|off|enabled|disabled].- Parameters:
property- The property sting to retrievedefaultValue- The default value for this property, if none is found- Returns:
- The prop value
- Throws:
Exception- If error
-