Class FileManager
java.lang.Object
br.net.dd.netherwingcore.common.serialization.FileManager
The FileManager class provides utility methods for reading and writing configuration data
to and from files. It ensures thread-safety by synchronizing write and read operations.
This class is designed to support configuration management in a structured and reliable way using key-value pair mappings. The key-value mappings are parsed according to the specified format in the file, and there is built-in handling for text and numeric value types.
Usage:
// Write a line to a file
FileManager.write("exampleKey=exampleValue", Paths.get("config.txt"));
// Read a file and retrieve key-value mappings
Mapinvalid input: '<'Key, Value> settings = FileManager.read(Paths.get("config.txt"));
This class is final and cannot be instantiated.-
Method Summary
-
Method Details
-
write
Appends a single line of text to the specified file.If the file does not exist, it will be created. If the file already exists, the line will be appended at the end of the file. The file is written using UTF-8 encoding.
- Parameters:
line- The line of text to write to the file. This should not be null.targetFile- The path to the file where the line will be written. Must be a valid file path.- Throws:
NullPointerException- IflineortargetFileis null.
-
read
Reads a configuration file and returns a map of key-value pairs.The input file is expected to have lines in the following format:
key=value
Comments (lines starting with `#`), empty lines, and lines containing `[` are ignored. Keys are wrapped in theKeyclass, and values are wrapped in theValueclass, with type information (e.g.,Type.TEXTorType.NUMBER).
-