public final class PropertiesUtil extends Object
Helps access properties. This utility provides a method to override system properties by specifying properties in a properties file.
| Constructor and Description |
|---|
PropertiesUtil(Properties
Constructs a PropertiesUtil using a given Properties object as its source of defined properties.
|
PropertiesUtil(String
Constructs a PropertiesUtil for a given properties file name on the classpath.
|
| Modifier and Type | Method and Description |
|---|---|
static Properties |
extractSubset(Properties
Extracts properties that start with or are equals to the specific prefix and returns them in a new Properties object with the prefix removed.
|
boolean |
getBooleanProperty(String
Gets the named property as a boolean value.
|
boolean |
getBooleanProperty(String
Gets the named property as a boolean value.
|
int |
getIntegerProperty(String
Gets the named property as an integer.
|
long |
getLongProperty(String
Gets the named property as a long.
|
static PropertiesUtil |
getProperties()
Returns the PropertiesUtil used by Log4j.
|
String |
getStringProperty(String
Gets the named property as a String.
|
String |
getStringProperty(String
Gets the named property as a String.
|
static Properties |
getSystemProperties()
Return the system properties or an empty Properties object if an error occurs.
|
boolean |
isOsWindows()
Returns true if system properties tell us we are running on Windows.
|
public PropertiesUtil(Propertiesprops)
props - the Properties to use by default
public PropertiesUtil(StringpropertiesFileName)
propertiesFileName - the location of properties file to load
public static PropertiesUtilgetProperties()
public StringgetStringProperty(String name)
name - the name of the property to look up
null if undefined.
public int getIntegerProperty(Stringname, int defaultValue)
name - the name of the property to look up
defaultValue - the default value to use if the property is undefined
defaultValue if it was undefined or could not be parsed.
public long getLongProperty(Stringname, long defaultValue)
name - the name of the property to look up
defaultValue - the default value to use if the property is undefined
defaultValue if it was undefined or could not be parsed.
public StringgetStringProperty(String name, String defaultValue)
name - the name of the property to look up
defaultValue - the default value to use if the property is undefined
defaultValue if undefined.
public boolean getBooleanProperty(Stringname)
"true" (case-insensitive), then it is returned as the boolean value
true. Any other non-
null text in the property is considered
false.
name - the name of the property to look up
false if undefined.
public boolean getBooleanProperty(Stringname, boolean defaultValue)
name - the name of the property to look up
defaultValue - the default value to use if the property is undefined
defaultValue if undefined.
public static PropertiesgetSystemProperties()
public static PropertiesextractSubset(Properties properties, String prefix)
properties - The Properties to evaluate.
prefix - The prefix to extract.
public boolean isOsWindows()