/**
   * Checks if the logs of the given run match any of the given patterns, line-by-line.
   *
   * @param matrixRun The run to be considered.
   * @param patterns The patterns to match with.
   * @return True if at least one line of the logs match at least one of the given patterns.
   * @throws IOException If there's a problem reading the log file.
   */
  private boolean matchesPattern(MatrixRun matrixRun, List<Pattern> patterns) throws IOException {
    if (patterns == null || patterns.isEmpty()) {
      return true; // No specific patterns specified. Accept everything.
    }

    BufferedReader reader =
        new BufferedReader(
            new InputStreamReader(
                new FileInputStream(matrixRun.getLogFile()), matrixRun.getCharset()));
    try {
      for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        for (Pattern pattern : patterns) {
          Matcher matcher = pattern.matcher(line);
          if (matcher.find()) {
            return true;
          }
        }
      }
    } finally {
      reader.close();
    }
    return false;
  }