public class PropertyHelper
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
PropertyHelper.PropertyInputStream |
Constructor and Description |
---|
PropertyHelper() |
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.lang.String> |
asMap(java.util.Properties p)
Convenience method to turn a Properties into a Map
|
static java.lang.String |
getPropertyIgnoringCase(java.util.Properties p,
java.lang.String key) |
static java.lang.String |
getPropertyIgnoringCase(java.util.Properties p,
java.lang.String key,
java.lang.String defaultValue)
Convenience method to get a property value ignoring the case.
|
static java.util.Properties |
getPropertySubset(java.util.Properties p,
java.lang.String prefix)
Get a subset of the configuration properties.
|
static java.util.Properties |
getPropertySubset(java.util.Properties p,
java.lang.String prefix,
boolean ignoreCase)
Get a subset of the configuration properties.
|
static java.util.Properties |
load(PropertyHelper.PropertyInputStream e)
Convenience method to load a set of properties from an InputStream
|
static java.util.Properties |
loadQuietly(java.lang.ClassLoader cl,
java.lang.String resource)
Convenience method to load a set of properties from a resource on the classpath.
|
static java.util.Properties |
loadQuietly(java.io.File file)
Convenience method to load a set of properties from a file.
|
static java.util.Properties |
loadQuietly(java.io.InputStream in)
Convenience method to load a set of properties from an InputStream
|
static java.util.Properties |
loadQuietly(PropertyHelper.PropertyInputStream e)
Convenience method to load a set of properties from an InputStream
|
static java.util.Properties |
loadQuietly(java.lang.String resource)
Convenience method to load a set of properties from a resource on the classpath.
|
static java.util.Properties |
loadQuietly(java.net.URL resource)
Convenience method to load a set of properties from a URL
|
public static java.util.Properties getPropertySubset(java.util.Properties p, java.lang.String prefix)
prefix
- the key that must exist in the property key for it to belong.p
- the propertiespublic static java.util.Properties getPropertySubset(java.util.Properties p, java.lang.String prefix, boolean ignoreCase)
prefix
- the key that must exist in the property key for it to belong.p
- the propertiesignoreCase
- whether or not to ignore the case of the prefix and property keypublic static java.lang.String getPropertyIgnoringCase(java.util.Properties p, java.lang.String key, java.lang.String defaultValue)
While we could legitimately override the get/set/getProperty/setProperty methods and convert all the keys to a single case; this would not be appropriate for the properties that we will convert into system properties. So we have a static method to iterate through all the keys of the property doing a case insensitive match. It's not terribly performant, but performance isn't a consideration at this point.
p
- the properties you want to query.key
- the keydefaultValue
- the default value if key is not matched.public static java.util.Map<java.lang.String,java.lang.String> asMap(java.util.Properties p)
p
- the properties, if null, will return an empty mappublic static java.lang.String getPropertyIgnoringCase(java.util.Properties p, java.lang.String key)
public static java.util.Properties loadQuietly(java.io.File file)
file
- the file.public static java.util.Properties loadQuietly(java.lang.String resource)
resource
- the resource that will be found via
Thread.currentThread().getContextClassLoader().getResourceAsStream(String)
.public static java.util.Properties loadQuietly(java.lang.ClassLoader cl, java.lang.String resource)
cl
- the classloader.resource
- the resource that will be found via
ClassLoader#getResourceAsStream(String)
.public static java.util.Properties loadQuietly(java.net.URL resource)
resource
- the resourcepublic static java.util.Properties loadQuietly(java.io.InputStream in)
in
- the inputstreampublic static java.util.Properties loadQuietly(PropertyHelper.PropertyInputStream e)
e
- the PropertyHelper.PropertyInputStream
instance (probably a lambda expression).public static java.util.Properties load(PropertyHelper.PropertyInputStream e) throws java.io.IOException
e
- the PropertyHelper.PropertyInputStream
instance (probably a lambda expression).java.io.IOException
- any IO exceptions reading the input stream.