Package jetbrains.buildServer.util
Class PropertiesUtil
- java.lang.Object
-
- jetbrains.buildServer.util.PropertiesUtil
-
public class PropertiesUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compareProperties(Map<String,String> props1, Map<String,String> props2)
Compares 2 maps of properties.static boolean
getBoolean(String value)
static Set<String>
getPropertyNames(Properties properties)
static byte[]
getUpdatedPropertiesArray(File propertiesFile, Properties newProperties)
Reads thepropertiesFile
properties, updates them with thenewProperties
and returns the byte array of the result with ISO-8859-1 encoding.static byte[]
getUpdatedPropertiesArray(File propertiesFile, Properties newProperties, String commentIfFileIsRecreated)
static boolean
isDifferent(Properties p1, Properties p2)
static boolean
isEmptyOrNull(String value)
static Properties
loadProperties(File propertiesFile)
static Properties
loadProperties(InputStream inputStream)
Load properties and closes the streamstatic Properties
loadPropertiesXml(File propertiesFile)
static Properties
loadPropertiesZipped(File propertiesFile)
static Integer
parseInt(String value)
static Long
parseLong(String value)
static void
storeProperties(Properties properties, File propertiesFile, String comment)
static void
storeProperties(Properties properties, OutputStream stream, String comment)
static void
storePropertiesXml(Properties properties, File propertiesFile, String comment)
static void
storePropertiesZipped(Properties properties, File propertiesFile, String comment)
static Map<String,String>
toMap(Properties properties)
static boolean
updateProperties(File propertiesFile, Properties newProperties, String commentIfFileIsRecreated)
static boolean
updatePropertiesFromFile(File propertiesFile, Map<String,String> propertiesToUpdate, Set<String> toRemove)
Updates properties file with respect to all comments, encodings
-
-
-
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)
-
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 mapprops2
- 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(File propertiesFile) throws IOException
- Throws:
IOException
-
loadPropertiesZipped
@NotNull public static Properties loadPropertiesZipped(File propertiesFile) throws IOException
- Throws:
IOException
-
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
-
loadPropertiesXml
@NotNull public static Properties loadPropertiesXml(File propertiesFile) throws IOException
- Throws:
IOException
-
toMap
@NotNull public static Map<String,String> toMap(@NotNull Properties properties)
-
storeProperties
public static void storeProperties(@NotNull Properties properties, @Nullable File propertiesFile, @Nullable String comment) throws IOException
- Throws:
IOException
-
storePropertiesZipped
public static void storePropertiesZipped(@NotNull Properties properties, @Nullable File propertiesFile, @Nullable String comment) throws IOException
- Throws:
IOException
-
storeProperties
public static void storeProperties(@NotNull Properties properties, @Nullable OutputStream stream, @Nullable String comment) throws IOException
- Throws:
IOException
-
storePropertiesXml
public static void storePropertiesXml(@NotNull Properties properties, @Nullable File propertiesFile, @Nullable String comment) throws IOException
- 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
- filepropertiesToUpdate
- properties to updatetoRemove
- 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 thepropertiesFile
properties, updates them with thenewProperties
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
-
-