public class PropertiesUtils extends Object
| Constructor and Description |
|---|
PropertiesUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
discover(Properties keys,
Properties[] sources,
boolean haltOnDiscovery)
Merges a set of properties from source Properties into a target
properties instance containing keys.
|
static String |
discover(String key,
Properties[] sources,
boolean haltOnDiscovery)
Discovers a value within a set of Properties either halting on the first
time the property is discovered or continuing on to take the last value
found for the property key.
|
static Properties |
findProperties(File dir,
String filename)
Create a new properties object and load the properties file if it exists
relative to [dir]/[filename] or [dir]/[filename].properties.
|
static Properties |
findUserProperties(String filename)
Loads a properties object in a properties file if it exists relative to
the filename ${user.home}.
|
static int |
get(Hashtable<String,Object> ht,
Object key,
int defval)
Gets a property or entry value from a hashtable and tries to transform
whatever the value may be to an primitive integer.
|
static boolean |
get(Properties props,
String key,
boolean defaultValue)
Gets a String property as a boolean returning a defualt if the key is not
present.
|
static byte |
get(Properties props,
String key,
byte defaultValue) |
static char |
get(Properties props,
String key,
char defaultValue) |
static long |
get(Properties props,
String key,
long defaultValue) |
static Properties |
getProperties(Class<?> clazz,
String path)
Loads a properties file as a class resource if it exists and returns an
empty Properties object otherwise.
|
static Properties |
getProperties(ClassLoader classloader,
String path)
Loads a properties file as a CL resource if it exists and returns an
empty Properties object otherwise.
|
static Properties |
getProperties(File file)
Creates a properties object and loads the properties in the file
otherwise and empty property object will be returned.
|
static Properties |
getStaticProperties(Class<?> ref)
Load a properties from a resource relative to a supplied class.
|
static Properties |
getStaticProperties(Class<?> ref,
String path)
Load properties from a resource relative to a supplied class and path.
|
static void |
macroExpand(Properties expanded,
Properties[] optionals)
Expands out a set of property key macros in the following format
${foo.bar} where foo.bar is a property key, by dereferencing the value of
the key using the original source Properties and other optional
Properties.
|
public static Properties findUserProperties(String filename)
filename - the properties file name with or without an extensionpublic static Properties findProperties(File dir, String filename)
dir - the base directoryfilename - the full fine name or the base name w/o the extensionpublic static Properties getStaticProperties(Class<?> ref)
ref - a class to use for relative path referencespublic static Properties getStaticProperties(Class<?> ref, String path)
ref - a class to use for relative path referencespath - the relative path to the resorucepublic static Properties getProperties(File file)
file - the properties filepublic static Properties getProperties(ClassLoader classloader, String path)
classloader - the loader to use for the resourcespath - the path to the resourcepublic static Properties getProperties(Class<?> clazz, String path)
clazz - the class to use for resolving the resourcespath - the relative path to the resourcepublic static void macroExpand(Properties expanded, Properties[] optionals)
expanded - the Properties to perform the macro expansion uponoptionals - null or an optional set of Properties to use for dereferencing
macro keys (foo.bar)public static String discover(String key, Properties[] sources, boolean haltOnDiscovery)
key - a property keysources - a set of source PropertieshaltOnDiscovery - true if we stop on finding a value, false otherwisepublic static void discover(Properties keys, Properties[] sources, boolean haltOnDiscovery)
keys - the keys to discover values forsources - the sources to searchhaltOnDiscovery - true to halt on first find or false to continue to last findpublic static boolean get(Properties props, String key, boolean defaultValue)
props - the properties to get the value fromkey - the property keydefaultValue - the default value to return if key is not presentpublic static int get(Hashtable<String,Object> ht, Object key, int defval)
ht - the hashtable to access for the valuekey - the key to use when accessing the htdefval - the default value to use if the key is not contained in ht or
if the value cannot be represented as a primitive integer.public static long get(Properties props, String key, long defaultValue)
public static byte get(Properties props, String key, byte defaultValue)
public static char get(Properties props, String key, char defaultValue)
Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.