Class PropsUtils

java.lang.Object
de.hsh.graja.util.PropsUtils

public class PropsUtils extends Object
  • Constructor Details

    • PropsUtils

      public PropsUtils()
  • Method Details

    • 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)
    • getDump

      public static String getDump(Map<String,String> map)
    • prettyMapToString

      public static <K, V> String prettyMapToString(Map<K,V> map)