コード例 #1
0
  public ArrayList<String> readFile(String filePath)
      throws java.io.FileNotFoundException, java.io.IOException {
    ArrayList<String> aList = new ArrayList<String>();

    try {
      final InputStream is = this.getClass().getResourceAsStream(filePath);
      try {
        final Reader r = new InputStreamReader(is);
        try {
          final BufferedReader br = new BufferedReader(r);
          try {
            String line = null;
            while ((line = br.readLine()) != null) {
              aList.add(line);
            }
            br.close();
            r.close();
            is.close();
          } finally {
            try {
              br.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        } finally {
          try {
            r.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      } finally {
        try {
          is.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    } catch (IOException e) {
      // failure
      e.printStackTrace();
    }

    return aList;
  }
コード例 #2
0
ファイル: JazzClient.java プロジェクト: joetopshot/rtc-plugin
  /**
   * **************************************************
   *
   * <p>private <T> T execute(ParseableCommand<T> cmd) throws IOException, InterruptedException {
   *
   * <p>**************************************************
   */
  private <T> T execute(ParseableCommand<T> cmd, String jazzExecutable)
      throws IOException, InterruptedException {
    // output to console.
    PrintStream output = listener.getLogger();
    // output.println("  RTC SCM - Jazz Client: Execute.");

    BufferedReader in =
        new BufferedReader(
            new InputStreamReader(
                new ByteArrayInputStream(popen(cmd.getArguments(), jazzExecutable).toByteArray())));
    T result;

    try {
      result = cmd.parse(in);
    } catch (Exception e) {
      throw new IOException(e);
    } finally {
      in.close();
    }

    return result;
  }
  /**
   * 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;
  }