Class PropertiesUtil


  • public class PropertiesUtil
    extends Object
    • Method Detail

      • getBoolean

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

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

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

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

        public static int compareProperties​(@NotNull
                                            Map<String,​String> props1,
                                            @NotNull
                                            Map<String,​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 Properties loadProperties​(@Nullable
                                                InputStream inputStream)
                                         throws IOException
        Load properties and closes the stream
        Parameters:
        inputStream - stream
        Returns:
        loaded properties file
        Throws:
        IOException
      • isDifferent

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

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

        public static boolean updatePropertiesFromFile​(@NotNull
                                                       File propertiesFile,
                                                       @NotNull
                                                       Map<String,​String> propertiesToUpdate,
                                                       @NotNull
                                                       Set<String> toRemove)
                                                throws 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:
        IOException - in error
      • updateProperties

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

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

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