Package jodd.util

Class PropertiesUtil


  • public class PropertiesUtil
    extends java.lang.Object
    Misc java.util.Properties utils.
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertiesUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Properties createFromFile​(java.io.File file)
      Create properties from the file.
      static java.util.Properties createFromFile​(java.lang.String fileName)
      Create properties from the file.
      static java.util.Properties createFromString​(java.lang.String data)
      Creates properties from string.
      static java.lang.String getProperty​(java.util.Map map, java.lang.String key)
      Returns String property from a map.
      static java.lang.String getProperty​(java.util.Map map, java.lang.String key, java.lang.String defaultValue)
      Returns String property from a map.
      static void loadFromFile​(java.util.Properties p, java.io.File file)
      Loads properties from the file.
      static void loadFromFile​(java.util.Properties p, java.lang.String fileName)
      Loads properties from the file.
      static void loadFromString​(java.util.Properties p, java.lang.String data)
      Loads properties from string.
      static void resolveAllVariables​(java.util.Properties prop)
      Resolves all variables.
      static java.lang.String resolveProperty​(java.util.Map map, java.lang.String key)
      Returns property with resolved variables.
      static java.util.Properties subset​(java.util.Properties p, java.lang.String prefix, boolean stripPrefix)
      Creates new Properties object from the original one, by copying those properties that have specified first part of the key name.
      static void writeToFile​(java.util.Properties p, java.io.File file)
      Writes properties to a file.
      static void writeToFile​(java.util.Properties p, java.io.File file, java.lang.String header)
      Writes properties to a file.
      static void writeToFile​(java.util.Properties p, java.lang.String fileName)
      Writes properties to a file.
      static void writeToFile​(java.util.Properties p, java.lang.String fileName, java.lang.String header)
      Writes properties to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PropertiesUtil

        public PropertiesUtil()
    • Method Detail

      • createFromFile

        public static java.util.Properties createFromFile​(java.lang.String fileName)
                                                   throws java.io.IOException
        Create properties from the file.
        Parameters:
        fileName - properties file name to load
        Throws:
        java.io.IOException
      • createFromFile

        public static java.util.Properties createFromFile​(java.io.File file)
                                                   throws java.io.IOException
        Create properties from the file.
        Parameters:
        file - properties file to load
        Throws:
        java.io.IOException
      • loadFromFile

        public static void loadFromFile​(java.util.Properties p,
                                        java.lang.String fileName)
                                 throws java.io.IOException
        Loads properties from the file. Properties are appended to the existing properties object.
        Parameters:
        p - properties to fill in
        fileName - properties file name to load
        Throws:
        java.io.IOException
      • loadFromFile

        public static void loadFromFile​(java.util.Properties p,
                                        java.io.File file)
                                 throws java.io.IOException
        Loads properties from the file. Properties are appended to the existing properties object.
        Parameters:
        p - properties to fill in
        file - file to read properties from
        Throws:
        java.io.IOException
      • writeToFile

        public static void writeToFile​(java.util.Properties p,
                                       java.lang.String fileName)
                                throws java.io.IOException
        Writes properties to a file.
        Parameters:
        p - properties to write to file
        fileName - destination file name
        Throws:
        java.io.IOException
      • writeToFile

        public static void writeToFile​(java.util.Properties p,
                                       java.lang.String fileName,
                                       java.lang.String header)
                                throws java.io.IOException
        Writes properties to a file.
        Parameters:
        p - properties to write to file
        fileName - destination file name
        header - optional header
        Throws:
        java.io.IOException
      • writeToFile

        public static void writeToFile​(java.util.Properties p,
                                       java.io.File file)
                                throws java.io.IOException
        Writes properties to a file.
        Parameters:
        p - properties to write to file
        file - destination file
        Throws:
        java.io.IOException
      • writeToFile

        public static void writeToFile​(java.util.Properties p,
                                       java.io.File file,
                                       java.lang.String header)
                                throws java.io.IOException
        Writes properties to a file.
        Parameters:
        p - properties to write to file
        file - destination file
        header - optional header
        Throws:
        java.io.IOException
      • createFromString

        public static java.util.Properties createFromString​(java.lang.String data)
                                                     throws java.io.IOException
        Creates properties from string.
        Throws:
        java.io.IOException
      • loadFromString

        public static void loadFromString​(java.util.Properties p,
                                          java.lang.String data)
                                   throws java.io.IOException
        Loads properties from string.
        Throws:
        java.io.IOException
      • subset

        public static java.util.Properties subset​(java.util.Properties p,
                                                  java.lang.String prefix,
                                                  boolean stripPrefix)
        Creates new Properties object from the original one, by copying those properties that have specified first part of the key name. Prefix may be optionally stripped during this process.
        Parameters:
        p - source properties, from which new object will be created
        prefix - key names prefix
        Returns:
        subset properties
      • getProperty

        public static java.lang.String getProperty​(java.util.Map map,
                                                   java.lang.String key)
        Returns String property from a map. If key is not found, or if value is not a String, returns null. Mimics Property.getProperty but on map.
      • getProperty

        public static java.lang.String getProperty​(java.util.Map map,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
        Returns String property from a map.
        See Also:
        getProperty(java.util.Map, String)
      • resolveAllVariables

        public static void resolveAllVariables​(java.util.Properties prop)
        Resolves all variables.
      • resolveProperty

        public static java.lang.String resolveProperty​(java.util.Map map,
                                                       java.lang.String key)
        Returns property with resolved variables.