Class ConfigurationFactory

java.lang.Object
com.codingchili.core.files.ConfigurationFactory

public class ConfigurationFactory extends Object
Supports reading/writing to multiple configuration formats.
  • Constructor Details

    • ConfigurationFactory

      public ConfigurationFactory()
  • Method Details

    • add

      public static void add(FileStore store)
      Parameters:
      store - the new implementation to add.
    • supported

      public static Set<String> supported()
      Returns:
      a set of all supported file extensions. The file extension should include the dot if appropriate, for example .yaml.
    • get

      public static FileStore get(String path)
      Parameters:
      path - contains the file extension that is mapped to a filestore implementation
      Returns:
      a filestore that is capable of handling the file extension, throws an exception if none is registered.
    • readObject

      public static io.vertx.core.json.JsonObject readObject(String path)
      Reads a JsonObject from a specified application-relative path.
      Parameters:
      path - the path from where to load the json object. If the file does not exist or if it does not contain an extension - all supported extensions will be attempted.
      Returns:
      the loaded json object.
    • enumerate

      public static Stream<String> enumerate(String directory, boolean subdirs)
      Lists all items in the given directory of type file.
      Parameters:
      directory - the directory to enumerate
      subdirs - include subdirectories to the given directory.
      Returns:
      a list of absolute file paths.
    • readDirectoryTree

      public static Stream<io.vertx.core.json.JsonObject> readDirectoryTree(String path)
      Like readDirectory(String) but includes all subdirectories not starting with a '.'
      Parameters:
      path - the path to a directory tree to read.
      Returns:
      a list of json objects where each object corresponds to a file.
    • readDirectory

      public static Stream<io.vertx.core.json.JsonObject> readDirectory(String path)
      Reads a directory of json-files formatted as JsonObjects, ignores files starting with a '.'
      Parameters:
      path - the application-relative directory to read from.
      Returns:
      a list of json objects where each object corresponds to a file. returns nothing when more than zero files fails to load.
    • writeObject

      public static void writeObject(io.vertx.core.json.JsonObject json, String target)
      Writes a json-object to the given path.
      Parameters:
      json - the json-object to write.
      target - the path to where the json-object is written to.
      Throws:
      RuntimeException - on failure to write.
    • delete

      public static boolean delete(String path)
      Deletes the file at the given path.
      Parameters:
      path - to the file to be deleted.
      Returns:
      true if the file was deleted successfully.
    • exists

      public static boolean exists(String path)
      Parameters:
      path - the path to a file to check if it exists.
      Returns:
      true if the file exists.