Class PropertiesUtil


  • public class PropertiesUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compareProperties​(java.util.Map<java.lang.String,​java.lang.String> props1, java.util.Map<java.lang.String,​java.lang.String> props2)
      Compares 2 maps of properties.
      static boolean getBoolean​(java.lang.String value)  
      static java.util.Set<java.lang.String> getPropertyNames​(java.util.Properties properties)  
      static byte[] getUpdatedPropertiesArray​(java.io.File propertiesFile, java.util.Properties newProperties)
      Reads the propertiesFile properties, updates them with the newProperties and returns the byte array of the result with ISO-8859-1 encoding.
      static byte[] getUpdatedPropertiesArray​(java.io.File propertiesFile, java.util.Properties newProperties, java.lang.String commentIfFileIsRecreated)  
      static boolean isDifferent​(java.util.Properties p1, java.util.Properties p2)  
      static boolean isEmptyOrNull​(java.lang.String value)  
      static java.util.Properties loadProperties​(java.io.File propertiesFile)  
      static java.util.Properties loadProperties​(java.io.InputStream inputStream)
      Load properties and closes the stream
      static java.util.Properties loadPropertiesXml​(java.io.File propertiesFile)  
      static java.util.Properties loadPropertiesZipped​(java.io.File propertiesFile)  
      static java.lang.Integer parseInt​(java.lang.String value)  
      static java.lang.Long parseLong​(java.lang.String value)  
      static void storeProperties​(java.util.Properties properties, java.io.File propertiesFile, java.lang.String comment)  
      static void storeProperties​(java.util.Properties properties, java.io.OutputStream stream, java.lang.String comment)  
      static void storePropertiesXml​(java.util.Properties properties, java.io.File propertiesFile, java.lang.String comment)  
      static void storePropertiesZipped​(java.util.Properties properties, java.io.File propertiesFile, java.lang.String comment)  
      static java.util.Map<java.lang.String,​java.lang.String> toMap​(java.util.Properties properties)  
      static boolean updateProperties​(java.io.File propertiesFile, java.util.Properties newProperties, java.lang.String commentIfFileIsRecreated)  
      static boolean updatePropertiesFromFile​(java.io.File propertiesFile, java.util.Map<java.lang.String,​java.lang.String> propertiesToUpdate, java.util.Set<java.lang.String> toRemove)
      Updates properties file with respect to all comments, encodings
      • Methods inherited from class java.lang.Object

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

      • getBoolean

        @Contract("null -> false")
        public static boolean getBoolean​(@Nullable
                                         java.lang.String value)
      • isEmptyOrNull

        @Contract("null -> true")
        public static boolean isEmptyOrNull​(@Nullable
                                            java.lang.String value)
      • parseInt

        @Contract("null -> null")
        @Nullable
        public static java.lang.Integer parseInt​(@Nullable
                                                 java.lang.String value)
      • parseLong

        @Contract("null -> null")
        @Nullable
        public static java.lang.Long parseLong​(@Nullable
                                               java.lang.String value)
      • compareProperties

        public static int compareProperties​(@NotNull
                                            java.util.Map<java.lang.String,​java.lang.String> props1,
                                            @NotNull
                                            java.util.Map<java.lang.String,​java.lang.String> props2)
        Compares 2 maps of properties. a=b compared to a=b&c=d will return -1; a=b&c=d compared to empty map will return 1; a=b compared to c=d will return 0;
        Parameters:
        props1 - the first map
        props2 - the second map
        Returns:
        >0, if props1 is more specific properties set than props2, <0, if less specific, 0 if the difference cannot be determined
      • loadProperties

        @NotNull
        public static java.util.Properties loadProperties​(java.io.File propertiesFile)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • loadPropertiesZipped

        @NotNull
        public static java.util.Properties loadPropertiesZipped​(java.io.File propertiesFile)
                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • loadProperties

        @NotNull
        public static java.util.Properties loadProperties​(@Nullable
                                                          java.io.InputStream inputStream)
                                                   throws java.io.IOException
        Load properties and closes the stream
        Parameters:
        inputStream - stream
        Returns:
        loaded properties file
        Throws:
        java.io.IOException
      • loadPropertiesXml

        @NotNull
        public static java.util.Properties loadPropertiesXml​(java.io.File propertiesFile)
                                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • toMap

        @NotNull
        public static java.util.Map<java.lang.String,​java.lang.String> toMap​(@NotNull
                                                                                   java.util.Properties properties)
      • storeProperties

        public static void storeProperties​(@NotNull
                                           java.util.Properties properties,
                                           @Nullable
                                           java.io.File propertiesFile,
                                           @Nullable
                                           java.lang.String comment)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • storePropertiesZipped

        public static void storePropertiesZipped​(@NotNull
                                                 java.util.Properties properties,
                                                 @Nullable
                                                 java.io.File propertiesFile,
                                                 @Nullable
                                                 java.lang.String comment)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • storeProperties

        public static void storeProperties​(@NotNull
                                           java.util.Properties properties,
                                           @Nullable
                                           java.io.OutputStream stream,
                                           @Nullable
                                           java.lang.String comment)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • storePropertiesXml

        public static void storePropertiesXml​(@NotNull
                                              java.util.Properties properties,
                                              @Nullable
                                              java.io.File propertiesFile,
                                              @Nullable
                                              java.lang.String comment)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • isDifferent

        public static boolean isDifferent​(@NotNull
                                          java.util.Properties p1,
                                          @NotNull
                                          java.util.Properties p2)
      • getPropertyNames

        @NotNull
        public static java.util.Set<java.lang.String> getPropertyNames​(@NotNull
                                                                       java.util.Properties properties)
      • updatePropertiesFromFile

        public static boolean updatePropertiesFromFile​(@NotNull
                                                       java.io.File propertiesFile,
                                                       @NotNull
                                                       java.util.Map<java.lang.String,​java.lang.String> propertiesToUpdate,
                                                       @NotNull
                                                       java.util.Set<java.lang.String> toRemove)
                                                throws java.io.IOException
        Updates properties file with respect to all comments, encodings
        Parameters:
        propertiesFile - file
        propertiesToUpdate - properties to update
        toRemove - property names to remove. Those properties will be commented out form the file
        Returns:
        true if file was changed, false otherwise
        Throws:
        java.io.IOException - in error
      • updateProperties

        public static boolean updateProperties​(@NotNull
                                               java.io.File propertiesFile,
                                               @NotNull
                                               java.util.Properties newProperties,
                                               @Nullable
                                               java.lang.String commentIfFileIsRecreated)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getUpdatedPropertiesArray

        @Nullable
        public static byte[] getUpdatedPropertiesArray​(@NotNull
                                                       java.io.File propertiesFile,
                                                       @NotNull
                                                       java.util.Properties newProperties)
                                                throws java.io.IOException
        Reads the propertiesFile properties, updates them with the newProperties and returns the byte array of the result with ISO-8859-1 encoding.
        Throws:
        java.io.IOException
      • getUpdatedPropertiesArray

        @Nullable
        public static byte[] getUpdatedPropertiesArray​(@NotNull
                                                       java.io.File propertiesFile,
                                                       @NotNull
                                                       java.util.Properties newProperties,
                                                       @Nullable
                                                       java.lang.String commentIfFileIsRecreated)
                                                throws java.io.IOException
        Throws:
        java.io.IOException