Class DiffableProperties


public final class DiffableProperties extends Object
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:
  1. Always use UNIX newlines ('\n') on all platforms.
  2. Change Unicode escapes \\uHHHH to lower-case \\uhhhh for compatibility with native2ascii and files saved by NetBeans.
  3. 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:
  • Method Details

    • 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.
      The result, with DiffableProperties.FormatResult.getAfter() null when the file unmodified
    • main

      public static void main(String[] args)
      Rewrites the given files, if modified. Reads and writes the files in ISO8859-1 encoding.