java.lang.Object
com.aoapps.hodgepodge.util.DiffableProperties
Formats
Properties
files in a format to maximize the ability for
diff tools (like git diff
) to represent changes. This is
accomplished with the following steps:
- Always use UNIX newlines (
'\n'
) on all platforms. - Change Unicode escapes
\\uHHHH
to lower-case\\uhhhh
for compatibility withnative2ascii
and 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:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionformatProperties
(File file) Rewrites the given file, if modified.static String
formatProperties
(String properties) Formats a properties file provided as a String.static void
Rewrites the given files, if modified.
-
Method Details
-
formatProperties
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
Rewrites the given file, if modified. Reads and writes the files in ISO8859-1 encoding.- Returns:
- The result, with
DiffableProperties.FormatResult.getAfter()
null
when the file unmodified - Throws:
IOException
-
main
Rewrites the given files, if modified. Reads and writes the files in ISO8859-1 encoding.
-