Class MessageParser
java.lang.Object
net.vincent.communidirect.client.util.MessageParser
Converts between three representations of a staged message:
- Raw editor temp-file text (headers + delimiter + body)
StagedMessagein-memory object- TOML file on disk under
~/.communidirect/staged/
Temp-file format (written for the editor, read back after)
TARGET_IP: 127.0.0.1 PORT: 9833 KEY_NAME: vincent --- MESSAGE --- Your multi-line message goes here.
TOML format (persisted to disk)
target_ip = "127.0.0.1" port = 9833 key_name = "vincent" body = "Your multi-line\nmessage goes here."
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildTempFileContent(String defaultIp, int defaultPort) Produces the initial content of the temp file shown to the user in the external editor.static StagedMessageparseTempFile(String content) Parses the raw contents of the editor temp file into aStagedMessage.static StagedMessagereadStagedToml(Path tomlFile) Reads a staged TOML file from disk and deserialises it into aStagedMessage.static voidwriteStagedToml(StagedMessage msg, Path stagedDir, String filename) Serialises aStagedMessageto disk as a TOML file.
-
Method Details
-
buildTempFileContent
Produces the initial content of the temp file shown to the user in the external editor.- Parameters:
defaultIp- pre-filled default IPdefaultPort- pre-filled default port- Returns:
- multi-line string ready to be written to a temporary file
-
parseTempFile
Parses the raw contents of the editor temp file into aStagedMessage.- Parameters:
content- full file contents as returned byFiles.readString(java.nio.file.Path)- Returns:
- parsed staged message; fields may be empty if parsing fails
-
writeStagedToml
public static void writeStagedToml(StagedMessage msg, Path stagedDir, String filename) throws IOException Serialises aStagedMessageto disk as a TOML file.- Parameters:
msg- message to persiststagedDir- path to thestaged/directoryfilename- target filename (e.g."20260221_190501_127.0.0.1.toml")- Throws:
IOException- on any write error
-
readStagedToml
Reads a staged TOML file from disk and deserialises it into aStagedMessage.- Parameters:
tomlFile- path to the TOML file- Returns:
- parsed staged message
- Throws:
IOException- on any read error
-