Class PropertyFileUtils

java.lang.Object
rife.bld.extension.propertyfile.PropertyFileUtils

@NullMarked public final class PropertyFileUtils extends Object
Utility methods for PropertyFileOperation.
Since:
1.0
Author:
Erik C. Thauvin
  • Method Details

    • loadProperties

      public static void loadProperties(File file, Properties p) throws IOException
      Loads a properties file.

      If the file does not exist, no properties are loaded. The file will be created when saveProperties(File, String, Properties) is called.

      Parameters:
      file - the file location
      p - the properties to load into
      Throws:
      IOException - if an error occurred while reading the file
      NullPointerException - if file or p is null
    • processDate

      public static void processDate(Properties p, EntryDate entry) throws DateTimeException
      Processes a date properties.

      If no value is present and calc is defined, the calculation starts from ZonedDateTime.now(). This matches Ant <propertyfile> behavior. To fail on missing values, do not use calc without also setting defaultValue or newValue.

      Parameters:
      p - the properties
      entry - the EntryDate containing the properties edits
      Throws:
      DateTimeException - if a parsing or arithmetic error occurs
      IllegalArgumentException - if no value is configured and no calc is set
    • processInt

      public static void processInt(Properties p, EntryInt entry)
      Processes an integer properties.

      If no value is present and calc is defined, the calculation starts from 0. This matches Ant <propertyfile> behavior. To fail on missing values, do not use calc without also setting defaultValue or newValue.

      Parameters:
      p - the properties
      entry - the EntryInt containing the properties edits
      Throws:
      IllegalArgumentException - if no value is configured and no calc is set, or the value cannot be parsed as an integer
    • processString

      public static void processString(Properties p, Entry entry)
      Processes a string property.
      Parameters:
      p - the property
      entry - the Entry containing the property edits
      Throws:
      IllegalArgumentException - if no value is configured or the modify function fails/returns null
    • resolveValue

      @NullUnmarked public static Object resolveValue(String existing, Object defaultValue, Object newValue)
      Resolves the effective value using precedence: newValue → existing → defaultValue. null means the value is missing. Empty string "" is considered a valid value.
      Parameters:
      existing - the current persisted value; may be null if the key is absent
      defaultValue - the fallback used when both existing and newValue are null
      newValue - when non-null, always takes precedence
      Returns:
      the resolved object; null if all three arguments are null
    • saveProperties

      public static void saveProperties(File file, String comment, Properties props) throws IOException
      Saves a properties file atomically when possible.

      The method writes to a temporary file in the same directory, calls fsync, then performs an atomic move to replace the target. If the filesystem does not support atomic move or the directory does not allow renames, it falls back to a non-atomic overwrite.

      Parameters:
      file - the file location
      comment - the header comment
      props - the Properties to save into the file
      Throws:
      IOException - if an IO error occurs while writing the file