Class MessageParser

java.lang.Object
net.vincent.communidirect.client.util.MessageParser

public final class MessageParser extends Object
Converts between three representations of a staged message:
  1. Raw editor temp-file text (headers + delimiter + body)
  2. StagedMessage in-memory object
  3. 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 Details

    • buildTempFileContent

      public static String buildTempFileContent(String defaultIp, int defaultPort)
      Produces the initial content of the temp file shown to the user in the external editor.
      Parameters:
      defaultIp - pre-filled default IP
      defaultPort - pre-filled default port
      Returns:
      multi-line string ready to be written to a temporary file
    • parseTempFile

      public static StagedMessage parseTempFile(String content)
      Parses the raw contents of the editor temp file into a StagedMessage.
      Parameters:
      content - full file contents as returned by Files.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 a StagedMessage to disk as a TOML file.
      Parameters:
      msg - message to persist
      stagedDir - path to the staged/ directory
      filename - target filename (e.g. "20260221_190501_127.0.0.1.toml")
      Throws:
      IOException - on any write error
    • readStagedToml

      public static StagedMessage readStagedToml(Path tomlFile) throws IOException
      Reads a staged TOML file from disk and deserialises it into a StagedMessage.
      Parameters:
      tomlFile - path to the TOML file
      Returns:
      parsed staged message
      Throws:
      IOException - on any read error