Class ComputationExceptionBuilder


  • public class ComputationExceptionBuilder
    extends Object
    Used to ease the creation of a ComputationException. The builder provides methods to register logs and files from different sources.
    Author:
    Yichen TANG , Sylvain LECLERC
    • Constructor Detail

      • ComputationExceptionBuilder

        public ComputationExceptionBuilder()
        Initializes the builder, with no cause, no message and no logs.
      • ComputationExceptionBuilder

        public ComputationExceptionBuilder​(Throwable cause)
        Initializes the builder with the specified exception as the computation exception cause.
    • Method Detail

      • message

        public ComputationExceptionBuilder message​(@Nullable
                                                   String message)
        Defines the detail message of the created computation exception.
        Parameters:
        message - the detail message of the computation exception.
        Returns:
        this
      • addOutLogIfExists

        public ComputationExceptionBuilder addOutLogIfExists​(@Nullable
                                                             Path path)
        Reads the content of standard output file at specified path, assuming UTF-8 encoding. This log will be associated to the file name. If path is null or file does not exist, this is a no-op.
        Parameters:
        path - The path to the standard output file.
        Returns:
        this
      • addOutLog

        public ComputationExceptionBuilder addOutLog​(String logName,
                                                     @Nullable
                                                     String log)
        Adds a standard output log to collected data.
        Parameters:
        logName - the log name, must not be null
        log - log content, may be null
        Returns:
        this
      • addErrLogIfExists

        public ComputationExceptionBuilder addErrLogIfExists​(@Nullable
                                                             Path path)
        Reads the content of standard error file at specified path, assuming UTF-8 encoding. This log will be associated to the file name. If path is null or file does not exist, this is a no-op.
        Parameters:
        path - The path to the standard error file.
        Returns:
        this
      • addErrLog

        public ComputationExceptionBuilder addErrLog​(String logName,
                                                     @Nullable
                                                     String log)
        Adds an error log to collected data.
        Parameters:
        logName - the log name, must not be null
        log - log content, may be null
        Returns:
        this
      • addFileIfExists

        public ComputationExceptionBuilder addFileIfExists​(@Nullable
                                                           Path path)
        Adds the content of a the file at specified path to collected data. It will be associated to the file name. If path is null or file does not exist, this is a no-op.
        Parameters:
        path - to the file to be added to collected data.
        Returns:
        this
      • addBytes

        public ComputationExceptionBuilder addBytes​(String key,
                                                    byte[] bytes)
        Adds raw content of a file to collected data.
        Parameters:
        key - The log file name.
        bytes - Bytes.
        Returns:
        this
      • build

        public ComputationException build()
        Creates the computation exception.
        Returns:
        the created computation exception.