Class PropertiesConfiguration.JupIOFactory

  • All Implemented Interfaces:
    PropertiesConfiguration.IOFactory
    Enclosing class:
    PropertiesConfiguration

    public static class PropertiesConfiguration.JupIOFactory
    extends java.lang.Object
    implements PropertiesConfiguration.IOFactory
    An alternative PropertiesConfiguration.IOFactory that tries to mimic the behavior of Properties (Jup) more closely. The goal is to allow both of them be used interchangeably when reading and writing properties files without losing or changing information.

    It also has the option to not use Unicode escapes. When using UTF-8 encoding (which is e.g. the new default for resource bundle properties files since Java 9), Unicode escapes are no longer required and avoiding them makes properties files more readable with regular text editors.

    Some of the ways this implementation differs from PropertiesConfiguration.DefaultIOFactory:

    • Trailing whitespace will not be trimmed from each line.
    • Unknown escape sequences will have their backslash removed.
    • \b is not a recognized escape sequence.
    • Leading spaces in property values are preserved by escaping them.
    • All natural lines (i.e. in the file) of a logical property line will have their leading whitespace trimmed.
    • Natural lines that look like comment lines within a logical line are not treated as such; they're part of the property value.
    Since:
    2.4
    • Field Detail

      • escapeUnicode

        private final boolean escapeUnicode
        Whether characters less than and characters greater than ~ in property keys or values should be escaped using Unicode escape sequences. Not necessary when e.g. writing as UTF-8.
    • Constructor Detail

      • JupIOFactory

        public JupIOFactory​(boolean escapeUnicode)
        Constructs a new PropertiesConfiguration.JupIOFactory with optional Unicode escaping. Whether Unicode escaping is required depends on the encoding used to save the properties file. E.g. for ISO-8859-1 this must be turned on, for UTF-8 it's not necessary. Unfortunately this factory can't determine the encoding on its own.
        Parameters:
        escapeUnicode - whether Unicode characters should be escaped