Package de.hsh.graja.util
Class PropsUtils
- java.lang.Object
-
- de.hsh.graja.util.PropsUtils
-
public class PropsUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description PropsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkKeys(Set<? extends Object> keys, Set<? extends Object> mandatoryKeys, Set<? extends Object> optionalKeys)
checks, whether keys contains all of the mandatoryKeys and no key not contained in mandatoryKeys or optionalKeys.static Map<String,String>
createPropertiesFromUTF8Stream(InputStream is)
reads key/value pairs from is and returns a map closes the input stream when finished.static String
getDump(Map<String,String> map)
static Map<String,String>
getMapStringStringView(Properties props)
static <T> T
getTypedValueOrDefault(Map<String,String> props, Object key, Usage usage, Class<T> type, T defaultVal)
Returns the value belonging to key from the props parameter.static <K,V>
StringprettyMapToString(Map<K,V> map)
static void
putAll(Properties from, Properties to)
-
-
-
Method Detail
-
createPropertiesFromUTF8Stream
public static Map<String,String> createPropertiesFromUTF8Stream(InputStream is)
reads key/value pairs from is and returns a map closes the input stream when finished.- Parameters:
is
-
-
getMapStringStringView
public static Map<String,String> getMapStringStringView(Properties props)
- Parameters:
props
-- Returns:
- a wrapper around props, that delivers values as Strings
-
checkKeys
public static void checkKeys(Set<? extends Object> keys, Set<? extends Object> mandatoryKeys, Set<? extends Object> optionalKeys) throws InvalidFormatException
checks, whether keys contains all of the mandatoryKeys and no key not contained in mandatoryKeys or optionalKeys.- Parameters:
keys
-mandatoryKeys
-optionalKeys
-- Throws:
InvalidFormatException
- if an invalid key was found in keys
-
getTypedValueOrDefault
public static <T> T getTypedValueOrDefault(Map<String,String> props, Object key, Usage usage, Class<T> type, T defaultVal) throws InvalidFormatException
Returns the value belonging to key from the props parameter. If the key does not exist in props, it depends:- If usage is optional, the defaultVal is returned
- otherwise an InvalidFormatException is thrown
- Parameters:
props
-key
-usage
-type
-defaultVal
-- Returns:
- The returned value will be converted from String to type T.
- Throws:
InvalidFormatException
- when a mandatory key is missing or when conversion to type failed.
-
putAll
public static void putAll(Properties from, Properties to)
-
-