Package com.powsybl.computation
Class ComputationExceptionBuilder
- java.lang.Object
-
- com.powsybl.computation.ComputationExceptionBuilder
-
public class ComputationExceptionBuilder extends Object
Used to ease the creation of aComputationException
. The builder provides methods to register logs and files from different sources.- Author:
- Yichen TANG
, Sylvain LECLERC
-
-
Constructor Summary
Constructors Constructor Description ComputationExceptionBuilder()
Initializes the builder, with no cause, no message and no logs.ComputationExceptionBuilder(Throwable cause)
Initializes the builder with the specified exception as the computation exception cause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ComputationExceptionBuilder
addBytes(String key, byte[] bytes)
Adds raw content of a file to collected data.ComputationExceptionBuilder
addErrLog(String logName, String log)
Adds an error log to collected data.ComputationExceptionBuilder
addErrLogIfExists(Path path)
Reads the content of standard error file at specified path, assuming UTF-8 encoding.ComputationExceptionBuilder
addFileIfExists(Path path)
Adds the content of a the file at specified path to collected data.ComputationExceptionBuilder
addOutLog(String logName, String log)
Adds a standard output log to collected data.ComputationExceptionBuilder
addOutLogIfExists(Path path)
Reads the content of standard output file at specified path, assuming UTF-8 encoding.ComputationException
build()
Creates the computation exception.ComputationExceptionBuilder
message(String message)
Defines the detail message of the created computation exception.
-
-
-
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 isnull
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 benull
log
- log content, may benull
- 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 isnull
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 benull
log
- log content, may benull
- 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 isnull
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.
-
-