Class PropertiesExtensions


  • public final class PropertiesExtensions
    extends java.lang.Object
    The Class PropertiesExtensions provides methods loading properties and other related operations for properties like find redundant values or getting all available languages from a bundle.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PROPERTIES_COMMENT_PATTERN
      The constant PROPERTIES_COMMENT_PATTERN is the regex pattern for find comments in properties file
      static java.lang.String[] PROPERTIES_DELIMITERS
      The constant PROPERTIES_DELIMITERS contains all valid delimiters for properties files
      static java.lang.String SEARCH_FILE_PATTERN
      The constant SEARCH_FILE_PATTERN is a regex for searching java and html files
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void export​(java.util.Properties properties, java.io.OutputStream outputStream)
      Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file.
      static void export​(java.util.Properties properties, java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment, boolean loadFromXML, boolean storeToXML)
      Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file.
      static void export​(java.util.Properties properties, java.io.OutputStream outputStream, java.lang.String comment)
      Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file.
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> findRedundantValues​(java.util.Properties properties)
      Finds redundant values from the given Properties object and saves it to a Map.
      static java.util.Optional<java.lang.Integer> getInteger​(java.util.Properties properties, java.lang.String propertiesKey)
      Try to get a number from the given properties key from the given properties.
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getMatchedPrefixLists​(java.util.Properties properties)
      Finds all keys with the same key prefixes from the given Properties and saves them to a Map with the prefix as a key and holds a List with the whole keys the starts with the same key prefix.
      static java.util.List<java.lang.String> getPropertyParameters​(java.lang.String propertyValue)
      Finds the property parameters from the given propertyValue.
      static java.util.Properties loadProperties​(java.io.File propertiesFile)
      Load a Properties-object from the given File-object.
      static java.util.Properties loadProperties​(java.io.File propertiesFile, boolean loadFromXML)
      Load a Properties-object from the given File-object.
      static void toProperties​(java.io.File properties, java.io.File xml, java.lang.String comment)
      Converts the given xml file to the given properties file.
      static void toProperties​(java.io.OutputStream properties, java.io.InputStream xml, java.lang.String comment)
      Converts the given xml InputStream to the given properties OutputStream.
      static void toProperties​(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment, boolean xmlFile)
      Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file.
      static void toPropertiesFile​(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment)
      Converts the given properties InputStream to the given properties OutputStream that represents the output file.
      static void toXml​(java.io.File properties, java.io.File xml, java.lang.String comment, java.lang.String encoding)
      Converts the given properties file to the given xml file.
      static void toXml​(java.io.InputStream properties, java.io.OutputStream xml, java.lang.String comment, java.lang.String encoding)
      Converts the given properties InputStream to the given xml OutputStream.
      • Methods inherited from class java.lang.Object

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

      • PROPERTIES_COMMENT_PATTERN

        public static final java.lang.String PROPERTIES_COMMENT_PATTERN
        The constant PROPERTIES_COMMENT_PATTERN is the regex pattern for find comments in properties file
        See Also:
        Constant Field Values
      • SEARCH_FILE_PATTERN

        public static final java.lang.String SEARCH_FILE_PATTERN
        The constant SEARCH_FILE_PATTERN is a regex for searching java and html files
        See Also:
        Constant Field Values
      • PROPERTIES_DELIMITERS

        public static final java.lang.String[] PROPERTIES_DELIMITERS
        The constant PROPERTIES_DELIMITERS contains all valid delimiters for properties files
    • Constructor Detail

      • PropertiesExtensions

        public PropertiesExtensions()
    • Method Detail

      • findRedundantValues

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> findRedundantValues​(java.util.Properties properties)
        Finds redundant values from the given Properties object and saves it to a Map.
        Parameters:
        properties - The Properties to check.
        Returns:
        A map that contains the redundant value as the key of the map and a List(as value of the map) of keys that have the redundant value.
      • getMatchedPrefixLists

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getMatchedPrefixLists​(java.util.Properties properties)
        Finds all keys with the same key prefixes from the given Properties and saves them to a Map with the prefix as a key and holds a List with the whole keys the starts with the same key prefix.
        Parameters:
        properties - the en properties
        Returns:
        the matched prefix lists
      • getPropertyParameters

        public static java.util.List<java.lang.String> getPropertyParameters​(java.lang.String propertyValue)
        Finds the property parameters from the given propertyValue.
        Parameters:
        propertyValue - the property value
        Returns:
        the property parameters as a list.
      • loadProperties

        public static java.util.Properties loadProperties​(java.io.File propertiesFile)
                                                   throws java.io.IOException
        Load a Properties-object from the given File-object.
        Parameters:
        propertiesFile - the properties file
        Returns:
        the properties or null if the file is not found.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static java.util.Properties loadProperties​(java.io.File propertiesFile,
                                                          boolean loadFromXML)
                                                   throws java.io.IOException
        Load a Properties-object from the given File-object.
        Parameters:
        propertiesFile - the properties file
        loadFromXML - the load from XML
        Returns:
        the properties or null if the file is not found.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toProperties

        public static void toProperties​(java.io.File properties,
                                        java.io.File xml,
                                        java.lang.String comment)
                                 throws java.io.IOException
        Converts the given xml file to the given properties file.
        Parameters:
        properties - the properties file. The xml file does not have to exist.
        xml - the xml file with the properties to convert.
        comment - the comment
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toProperties

        public static void toProperties​(java.io.OutputStream properties,
                                        java.io.InputStream xml,
                                        java.lang.String comment)
                                 throws java.io.IOException
        Converts the given xml InputStream to the given properties OutputStream.
        Parameters:
        properties - the properties file. The xml file does not have to exist.
        xml - the xml file with the properties to convert.
        comment - the comment
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toPropertiesFile

        public static void toPropertiesFile​(java.io.OutputStream outputStream,
                                            java.io.InputStream inputStream,
                                            java.lang.String comment)
                                     throws java.io.IOException
        Converts the given properties InputStream to the given properties OutputStream that represents the output file.
        Parameters:
        outputStream - the properties file. The xml file does not have to exist.
        inputStream - the xml file with the properties to convert.
        comment - the comment
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toProperties

        public static void toProperties​(java.io.OutputStream outputStream,
                                        java.io.InputStream inputStream,
                                        java.lang.String comment,
                                        boolean xmlFile)
                                 throws java.io.IOException
        Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file. The flag xmlFile tells if the output shell be an xml file or a properties file.
        Parameters:
        outputStream - the stream from the output properties file. If the file does not exists a new file will be created.
        inputStream - the stream from input file with the properties to convert
        comment - the comment
        xmlFile - the flag that tells if the output shell be an xml file if true otherwise it will be an properties file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • export

        public static void export​(java.util.Properties properties,
                                  java.io.OutputStream outputStream,
                                  java.io.InputStream inputStream,
                                  java.lang.String comment,
                                  boolean loadFromXML,
                                  boolean storeToXML)
                           throws java.io.IOException
        Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file.
        Parameters:
        properties - the properties to store
        outputStream - the stream from the output properties file. If the file does not exists a new file will be created.
        inputStream - the input stream
        comment - the comment
        loadFromXML - the flag that tells if the input shell be loaded from a XML file if true otherwise it will be loaded from a properties file
        storeToXML - the flag that tells if the output shell be stored to a XML file if true otherwise it will be stored to a properties file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • export

        public static void export​(java.util.Properties properties,
                                  java.io.OutputStream outputStream)
                           throws java.io.IOException
        Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file. The flag xmlFile tells if the output shell be an xml file or a properties file.
        Parameters:
        properties - the properties to store
        outputStream - the stream from the output properties file. If the file does not exists a new file will be created.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • export

        public static void export​(java.util.Properties properties,
                                  java.io.OutputStream outputStream,
                                  java.lang.String comment)
                           throws java.io.IOException
        Exports the given InputStream that represents a properties file to the given properties OutputStream that represents the output file. The flag xmlFile tells if the output shell be an xml file or a properties file.
        Parameters:
        properties - the properties to store
        outputStream - the stream from the output properties file. If the file does not exists a new file will be created.
        comment - the comment
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toXml

        public static void toXml​(java.io.File properties,
                                 java.io.File xml,
                                 java.lang.String comment,
                                 java.lang.String encoding)
                          throws java.io.IOException
        Converts the given properties file to the given xml file.
        Parameters:
        properties - the properties file.
        xml - the xml file to write in. The xml file does not have to exist.
        comment - the comment
        encoding - the encoding for the xml file.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • toXml

        public static void toXml​(java.io.InputStream properties,
                                 java.io.OutputStream xml,
                                 java.lang.String comment,
                                 java.lang.String encoding)
                          throws java.io.IOException
        Converts the given properties InputStream to the given xml OutputStream.
        Parameters:
        properties - the properties InputStream.
        xml - the xml OutputStream to write in.
        comment - the comment
        encoding - the encoding for the xml file.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getInteger

        public static java.util.Optional<java.lang.Integer> getInteger​(java.util.Properties properties,
                                                                       java.lang.String propertiesKey)
        Try to get a number from the given properties key from the given properties. If it does not exists an empty Optional will be returned and a log message will be logged.
        Parameters:
        properties - the properties
        propertiesKey - the properties key
        Returns:
        the Optional with the number or an empty Optional if the properties key has no number value or no value at all