Example #1
0
  /**
   * **************************************************
   *
   * <p>private ByteArrayOutputStream popen(ArgumentListBuilder args)
   *
   * <p>Runs the command and captures the output.
   *
   * <p>**************************************************
   */
  private ByteArrayOutputStream popen(ArgumentListBuilder args, String jazzExecutable)
      throws IOException, InterruptedException {
    try {

      // scm produces text in the platform default encoding, so we need to convert it back to UTF-8
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      WriterOutputStream o =
          new WriterOutputStream(
              new OutputStreamWriter(baos, "UTF-8"), java.nio.charset.Charset.forName("UTF-8"));

      PrintStream output = listener.getLogger();

      ForkOutputStream fos = new ForkOutputStream(o, output);
      ProcStarter pstarter = run(args, jazzExecutable);

      if (joinWithPossibleTimeout(pstarter.stdout(fos), listener, null) == 0) {
        o.flush();
        return baos;
      } else {
        String errorString = "Failed to run ";
        boolean[] maskArray = args.toMaskArray();
        String[] cmdArray = args.toCommandArray();

        for (int i = 0; i < maskArray.length; i++) {
          if (maskArray[i] == false) {
            errorString += cmdArray[i] + " ";
          } else {
            errorString += "**** ";
          }
        }

        listener.error(errorString);
        throw new AbortException();
      }
    } catch (Exception e) {
      listener.error("Exception in popen " + e);
      throw new AbortException();
    }
  }
Example #2
0
 /**
  * Opens a BufferedReader.
  *
  * @return the reader
  */
 public BufferedReader openReader() {
   java.nio.charset.Charset charset = java.nio.charset.Charset.forName(encoding);
   InputStream stream = openInputStream();
   if (stream == null) return null;
   return new BufferedReader(new InputStreamReader(stream, charset));
 }