Package org.teiid.core.util
Class PropertiesUtils
- java.lang.Object
-
- org.teiid.core.util.PropertiesUtils
-
public final class PropertiesUtils extends Object
Static utility methods for common tasks having to do with java.util.Properties.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PropertiesUtils.InvalidPropertyException
-
Constructor Summary
Constructors Constructor Description PropertiesUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Properties
clone(Properties props)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object.static Properties
clone(Properties props, Properties defaults, boolean deepClone)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object.static byte[]
fromHex(String hex)
Return the bytes for a given hex string, or throw anIllegalArgumentException
static boolean
getBooleanProperty(Properties props, String propName, boolean defaultValue)
static Properties
getDefaultProperties()
static double
getDoubleProperty(Properties props, String propName, double defaultValue)
static float
getFloatProperty(Properties props, String propName, float defaultValue)
static String
getHierarchicalProperty(String key, String defaultValue)
Search for the property first in the environment, then in the system propertiesstatic <T> T
getHierarchicalProperty(String key, T defaultValue, Class<T> clazz)
Search for the property first in the environment, then in the system propertiesstatic int
getIntProperty(Properties props, String propName, int defaultValue)
static long
getLongProperty(Properties props, String propName, long defaultValue)
static Properties
load(String fileName)
static void
putAll(Properties addToThis, Properties withThese)
This method is intended to replace the use of theputAll
method ofProperties
inherited fromjava.util.Hashtable
.static void
setBeanProperties(Object bean, Properties props, String prefix)
static void
setBeanProperties(Object bean, Properties props, String prefix, boolean includeEnv)
static void
setBeanProperty(Object bean, String name, Object value)
static String
toHex(byte[] bytes)
static char
toHex(int nibble)
Convert a nibble to a hex characterstatic void
toHex(StringBuilder sb, InputStream is)
-
-
-
Method Detail
-
clone
public static Properties clone(Properties props)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object.
-
clone
public static Properties clone(Properties props, Properties defaults, boolean deepClone)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object.
-
putAll
public static void putAll(Properties addToThis, Properties withThese)
This method is intended to replace the use of the
putAll
method ofProperties
inherited fromjava.util.Hashtable
. The problem with that method is that, since it is inherited fromHashtable
, default properties are lost.For example, the following code
will fail ifProperties a; Properties b; //initialize ... a.putAll(b);
b
had been constructed with a defaultProperties
object. Those defaults would be lost and not added toa
.The above code could be correctly performed with this method, like this:
In the above example,Properties a; Properties b; //initialize ... PropertiesUtils.putAll(a,b);
a
is modified - properties are added to it (note that ifa
has defaults they will remain unaffected.) The properties fromb
, including defaults, will be added toa
using itssetProperty
method - these new properties will overwrite any pre-existing ones of the same name.- Parameters:
addToThis
- This Properties object is modified; the properties of the other parameter are added to this. The added property values will replace any current property values of the same names.withThese
- The properties (including defaults) of this object are added to the "addToThis" parameter.
-
getIntProperty
public static int getIntProperty(Properties props, String propName, int defaultValue) throws PropertiesUtils.InvalidPropertyException
-
getLongProperty
public static long getLongProperty(Properties props, String propName, long defaultValue)
-
getFloatProperty
public static float getFloatProperty(Properties props, String propName, float defaultValue)
-
getDoubleProperty
public static double getDoubleProperty(Properties props, String propName, double defaultValue)
-
getBooleanProperty
public static boolean getBooleanProperty(Properties props, String propName, boolean defaultValue)
-
load
public static Properties load(String fileName) throws IOException
- Throws:
IOException
-
toHex
public static char toHex(int nibble)
Convert a nibble to a hex character- Parameters:
nibble
- the nibble to convert.
-
toHex
public static String toHex(byte[] bytes)
-
fromHex
public static byte[] fromHex(String hex)
Return the bytes for a given hex string, or throw anIllegalArgumentException
- Parameters:
hex
-- Returns:
-
toHex
public static void toHex(StringBuilder sb, InputStream is) throws IOException
- Throws:
IOException
-
setBeanProperties
public static void setBeanProperties(Object bean, Properties props, String prefix)
-
setBeanProperties
public static void setBeanProperties(Object bean, Properties props, String prefix, boolean includeEnv)
-
getHierarchicalProperty
public static String getHierarchicalProperty(String key, String defaultValue)
Search for the property first in the environment, then in the system properties- Parameters:
key
-defaultValue
-- Returns:
-
getHierarchicalProperty
public static <T> T getHierarchicalProperty(String key, T defaultValue, Class<T> clazz)
Search for the property first in the environment, then in the system properties- Parameters:
key
-defaultValue
-clazz
-- Returns:
-
getDefaultProperties
public static Properties getDefaultProperties()
-
-