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 classPropertiesUtils.InvalidPropertyException
-
Constructor Summary
Constructors Constructor Description PropertiesUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Propertiesclone(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 Propertiesclone(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 anIllegalArgumentExceptionstatic booleangetBooleanProperty(Properties props, String propName, boolean defaultValue)static PropertiesgetDefaultProperties()static doublegetDoubleProperty(Properties props, String propName, double defaultValue)static floatgetFloatProperty(Properties props, String propName, float defaultValue)static StringgetHierarchicalProperty(String key, String defaultValue)Search for the property first in the environment, then in the system propertiesstatic <T> TgetHierarchicalProperty(String key, T defaultValue, Class<T> clazz)Search for the property first in the environment, then in the system propertiesstatic intgetIntProperty(Properties props, String propName, int defaultValue)static longgetLongProperty(Properties props, String propName, long defaultValue)static Propertiesload(String fileName)static voidputAll(Properties addToThis, Properties withThese)This method is intended to replace the use of theputAllmethod ofPropertiesinherited fromjava.util.Hashtable.static voidsetBeanProperties(Object bean, Properties props, String prefix)static voidsetBeanProperties(Object bean, Properties props, String prefix, boolean includeEnv)static voidsetBeanProperty(Object bean, String name, Object value)static StringtoHex(byte[] bytes)static chartoHex(int nibble)Convert a nibble to a hex characterstatic voidtoHex(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
putAllmethod ofPropertiesinherited 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);bhad been constructed with a defaultPropertiesobject. 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);ais modified - properties are added to it (note that ifahas defaults they will remain unaffected.) The properties fromb, including defaults, will be added toausing itssetPropertymethod - 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()
-
-