Class Utils

java.lang.Object
eu.svjatoslav.alyverkko_cli.Utils

public class Utils extends Object

General utility functions for the Älyverkko CLI application. Currently provides ANSI color output capabilities for console messages.

Color formatting follows standard ANSI escape sequences, with specific methods for common message types like errors.

For future extensions, this class could include additional helper functions for file operations or string processing.

  • Field Details

    • DEFAULT_CONFIG_FILE_PATH

      public static final String DEFAULT_CONFIG_FILE_PATH
      The default path for the YAML config file, typically under the user's home directory.
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • printRedMessageToConsole

      public static void printRedMessageToConsole(String message)
      Prints a message in red text to the console.
      Parameters:
      message - the text to print in red.
    • getFirstLine

      public static String getFirstLine(File file) throws IOException
      Reads the first line of a file.
      Parameters:
      file - File to read
      Returns:
      First line of file or null if empty
      Throws:
      IOException - if file reading fails
    • fileHasToComputeMarker

      public static boolean fileHasToComputeMarker(File file) throws IOException
      Inspects the first line of the file to see if it starts with "TOCOMPUTE:".
      Parameters:
      file - the file to read.
      Returns:
      true if the file's first line starts with "TOCOMPUTE:".
      Throws:
      IOException - if file reading fails.
    • loadConfiguration

      public static Configuration loadConfiguration(File configFile) throws IOException
      Loads the configuration from a given file, or from the default path if configFile is null.
      Parameters:
      configFile - the file containing the YAML config; may be null.
      Returns:
      the Configuration object, or null if not found/invalid.
      Throws:
      IOException - if file I/O fails during reading.
    • getConfigurationFile

      public static File getConfigurationFile(eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileOption configFileOption)
      Returns the configuration file from the given option, or the default path if not present.
      Parameters:
      configFileOption - the CLI option for the config file.
      Returns:
      the configuration file to load.