Class PropsIO


  • public final class PropsIO
    extends Object

    Utility for handling java.util.Property objects.

    Author:
    Fugerit
    • Method Detail

      • fill

        public static void fill​(Properties from,
                                Properties to)

        Copy all entries from a java.util.Properties to another.

        No check is made for overwritten entries.

        Parameters:
        from - source object
        to - destination object
        See Also:
        ClassHelper
      • loadFromClassLoaderSafe

        public static Properties loadFromClassLoaderSafe​(String path)

        Load a java.util.Properties from the DefaultClassLoader.

        Parameters:
        path - the path
        Returns:
        the java.util.Properties object
      • loadFromClassLoader

        public static Properties loadFromClassLoader​(String path)
                                              throws IOException

        Load a java.util.Properties from the DefaultClassLoader.

        Parameters:
        path - the path
        Returns:
        the java.util.Properties object
        Throws:
        IOException - in case of troubles during the operation
      • loadFromURL

        public static Properties loadFromURL​(String u)
                                      throws IOException

        Load a java.util.Properties from an URL.

        Parameters:
        u - the url
        Returns:
        the java.util.Properties object
        Throws:
        IOException - in case of troubles during the operation
      • loadFromURL

        public static Properties loadFromURL​(URL u)
                                      throws IOException

        Load a java.util.Properties from an URL.

        Parameters:
        u - the url
        Returns:
        the java.util.Properties object
        Throws:
        IOException - in case of troubles during the operation
      • loadFromFile

        public static Properties loadFromFile​(String f)
                                       throws IOException

        Load a java.util.Properties from a File.

        Parameters:
        f - the file
        Returns:
        the java.util.Properties object
        Throws:
        IOException - in case of troubles during the operation
      • loadFromFileSafe

        public static Properties loadFromFileSafe​(String f)

        Load a java.util.Properties from a File.

        Parameters:
        f - the file
        Returns:
        the java.util.Properties object
      • loadFromFile

        public static Properties loadFromFile​(File f)
                                       throws IOException

        Load a java.util.Properties from a File.

        Parameters:
        f - the file
        Returns:
        the java.util.Properties object
        Throws:
        IOException - in case of troubles during the operation
      • loadFromStream

        public static Properties loadFromStream​(InputStream is)
                                         throws IOException

        Load a java.util.Properties from a Stream.

        Parameters:
        is - the stream
        Returns:
        the java.util.Properties object
        Throws:
        IOException - in case of troubles during the operation
      • subProps

        public static Properties subProps​(Properties props,
                                          String basePrefix,
                                          String separator)
        Return a new java.util.Properties object containing only the properties with given prefix. NOTE: by default prefix is removed in resulting Properties NOTE: prefix is build as basePrefix+separator
        Parameters:
        props - input java.util.Properties
        basePrefix - base prefix to use for searching keys
        separator - separator to use for searching keys
        Returns:
        resulting java.util.Properties
      • subProps

        public static Properties subProps​(Properties props,
                                          String basePrefix,
                                          String separator,
                                          boolean removePrefix)
        Return a new java.util.Properties object containing only the properties with given prefix. NOTE: prefix is build as basePrefix+separator
        Parameters:
        props - input java.util.Properties
        basePrefix - base prefix to use for searching keys
        separator - separator to use for searching keys
        removePrefix - true in case you want to remove the prefix from keys in the resulting Properties
        Returns:
        resulting java.util.Properties
      • subProps

        public static Properties subProps​(Properties props,
                                          String prefix)
        Return a new java.util.Properties object containing only the properties with given prefix. NOTE: by default prefix is removed in resulting Properties
        Parameters:
        props - input java.util.Properties
        prefix - prefix for the keys to search
        Returns:
        resulting java.util.Properties
      • subProps

        public static Properties subProps​(Properties props,
                                          String prefix,
                                          boolean removePrefix)
        Return a new java.util.Properties object containing only the properties with given prefix.
        Parameters:
        props - input java.util.Properties
        prefix - prefix for the keys to search
        removePrefix - true in case you want to remove the prefix from keys in the resulting Properties
        Returns:
        resulting java.util.Properties