Package com.codingchili.core.files
Class ConfigurationFactory
java.lang.Object
com.codingchili.core.files.ConfigurationFactory
Supports reading/writing to multiple configuration formats.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
static boolean
Deletes the file at the given path.Lists all items in the given directory of type file.static boolean
static FileStore
static Stream<io.vertx.core.json.JsonObject>
readDirectory(String path)
Reads a directory of json-files formatted as JsonObjects, ignores files starting with a '.'static Stream<io.vertx.core.json.JsonObject>
readDirectoryTree(String path)
LikereadDirectory(String)
but includes all subdirectories not starting with a '.'static io.vertx.core.json.JsonObject
readObject(String path)
Reads a JsonObject from a specified application-relative path.static void
writeObject(io.vertx.core.json.JsonObject json, String target)
Writes a json-object to the given path.
-
Constructor Details
-
ConfigurationFactory
public ConfigurationFactory()
-
-
Method Details
-
add
- Parameters:
store
- the new implementation to add.
-
supported
- Returns:
- a set of all supported file extensions. The file extension should include the dot if appropriate, for example .yaml.
-
get
- 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
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
Lists all items in the given directory of type file.- Parameters:
directory
- the directory to enumeratesubdirs
- include subdirectories to the given directory.- Returns:
- a list of absolute file paths.
-
readDirectoryTree
LikereadDirectory(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
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
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
Deletes the file at the given path.- Parameters:
path
- to the file to be deleted.- Returns:
- true if the file was deleted successfully.
-
exists
- Parameters:
path
- the path to a file to check if it exists.- Returns:
- true if the file exists.
-