Package com.aoindustries.util
Class DiffableProperties
- java.lang.Object
-
- com.aoindustries.util.DiffableProperties
-
public class DiffableProperties extends Object
FormatsPropertiesfiles in a format to maximize the ability for diff tools (likegit diff) to represent changes. This is accomplished with the following steps:- Always use UNIX newlines (
'\n') on all platforms. - Change Unicode escapes
\\uHHHHto lower-case\\uhhhhfor compatibility withnative2asciiand files saved by NetBeans. - Make all multi-line values span multiple lines. Add an escaped newline after any "\n" that is not at the end of the line already. The next line will be prefixed with a "\" if it starts with whitespace.
For maximum diffability, this should be used along with
SortedProperties.- See Also:
Properties,SortedProperties
- Always use UNIX newlines (
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDiffableProperties.FormatResult
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DiffableProperties.FormatResultformatProperties(File file)Rewrites the given file, if modified.static StringformatProperties(String properties)Formats a properties file provided as a String.static voidmain(String[] args)Rewrites the given files, if modified.
-
-
-
Method Detail
-
formatProperties
public static String formatProperties(String properties)
Formats a properties file provided as a String. The file may contain Unicode values as supported by Java 9+.The file encoding is not performed by this method. For Java <= 8, this should be stored in the ISO8859-1 encoding. For Java >= 9, this may be stored in the UTF-8 encoding.
-
formatProperties
public static DiffableProperties.FormatResult formatProperties(File file) throws IOException
Rewrites the given file, if modified. Reads and writes the files in ISO8859-1 encoding.- Returns:
- The result, with
DiffableProperties.FormatResult.getAfter()nullwhen the file unmodified - Throws:
IOException
-
main
public static void main(String[] args)
Rewrites the given files, if modified. Reads and writes the files in ISO8859-1 encoding.
-
-