Package com.mooltiverse.oss.nyx.io
Class FileMapper
java.lang.Object
com.mooltiverse.oss.nyx.io.FileMapper
This class is used to load and save data files like configuration or state files.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TUnmarshals the content of the given file to an object of the given type.static <T> TUnmarshals the content of the given URL to an object of the given type.static voidMarshals the content of the given object to a file represented by the given path.
-
Method Details
-
load
Unmarshals the content of the given file to an object of the given type.- Type Parameters:
T- the type of object to unmarshal.- Parameters:
file- the file to load from. The file path must end with one of the supported extensions:json,yaml,yml(or JSON is used by default).type- the class representing the type of object to unmarshal.- Returns:
- the object instance unmarshalled from the given file.
- Throws:
DataAccessException- in case of any exception due to data accessIllegalArgumentException- if the given file path does not contain a supported extension
-
load
Unmarshals the content of the given URL to an object of the given type.- Type Parameters:
T- the type of object to unmarshal.- Parameters:
url- the URL to load from. The file path must end with one of the supported extensions:json,yaml,yml(or JSON is used by default).type- the class representing the type of object to unmarshal.- Returns:
- the object instance unmarshalled from the given URL.
- Throws:
DataAccessException- in case of any exception due to data accessIllegalArgumentException- if the given file path does not contain a supported extension
-
save
Marshals the content of the given object to a file represented by the given path.- Parameters:
filePath- the path of the file to save to. If it's a relative path it will be considered relative to the current working directory. The file path must end with one of the supported extensions:json,yaml,yml(or JSON is used by default).content- the object to marshal.- Throws:
DataAccessException- in case of any exception due to data accessIllegalArgumentException- if the given file path does not contain a supported extension
-