Used when the reault file contains binary data.
@param process
@param builder
@param outPutFiles
@return Binary results
@throws Exception if process has non 0 value or no logs found then throw exception
545826
private byte[] collectProcessResultsBytes(Process process, ProcessBuilder builder,
      SubProcessIOFiles outPutFiles) throws Exception {

    Byte[] results;

    try {

      LOG.debug(String.format("Executing process %s", createLogEntryFromInputs(builder.command())));

      // If process exit value is not 0 then subprocess failed, record logs
      if (process.exitValue() != 0) {
        outPutFiles.copyOutPutFilesToBucket(configuration, FileUtils.toStringParams(builder));
        String log = createLogEntryForProcessFailure(process, builder.command(), outPutFiles);
        throw new Exception(log);
      }

      // If no return file then either something went wrong or the binary is setup incorrectly for
      // the ret file either way throw error
      if (!Files.exists(outPutFiles.resultFile)) {
        String log = createLogEntryForProcessFailure(process, builder.command(), outPutFiles);
        outPutFiles.copyOutPutFilesToBucket(configuration, FileUtils.toStringParams(builder));
        throw new Exception(log);
      }

      // Everything looks healthy return bytes
      return Files.readAllBytes(outPutFiles.resultFile);

    } catch (Exception ex) {
      String log = String.format("Unexpected error runnng process. %s error message was %s",
          createLogEntryFromInputs(builder.command()), ex.getMessage());
      throw new Exception(log);
    }
  }
496514
public static void main(String[] args) throws Exception {
    Builder builder = Builder.newBuilder();

    /**
     * The processing graph consists of a supplier streamlet that emits
     * random integers between 1 and 100. From there, a series of transformers
     * is applied. At the end of the graph, the original value is ultimately
     * unchanged.
     */
    builder.newSource(() -> ThreadLocalRandom.current().nextInt(100))
        .transform(new DoNothingTransformer<>())
        .transform(new IncrementTransformer(10))
        .transform(new IncrementTransformer(-7))
        .transform(new DoNothingTransformer<>())
        .transform(new IncrementTransformer(-3))
        .log();

    Config config = Config.defaultConfig();

    // Fetches the topology name from the first command-line argument
    String topologyName = StreamletUtils.getTopologyName(args);

    // Finally, the processing graph and configuration are passed to the Runner, which converts
    // the graph into a Heron topology that can be run in a Heron cluster.
    new Runner().run(topologyName, config, builder);
  }
1338644
public static void exec(ProcessBuilder pb) throws IOException
    {
        Process p = pb.start();
        try
        {
            int errCode = p.waitFor();
            if (errCode != 0)
            {
                BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                StringBuilder sb = new StringBuilder();
                String str;
                while ((str = in.readLine()) != null)
                    sb.append(str).append(System.getProperty("line.separator"));
                while ((str = err.readLine()) != null)
                    sb.append(str).append(System.getProperty("line.separator"));
                throw new IOException("Exception while executing the command: "+ StringUtils.join(pb.command(), " ") +
                                      ", command error Code: " + errCode +
                                      ", command output: "+ sb.toString());
            }
        }
        catch (InterruptedException e)
        {
            throw new AssertionError(e);
        }
    }
1031641
String getProcErrorOutput(Process proc) throws IOException {
        StringBuffer output = new StringBuffer();

        InputStream procIn = proc.getInputStream();
        int read;
        // Dump the data printed by the process
        do {
            byte[] buffer = new byte[BUFFER_SIZE];
            read = procIn.read(buffer);
            String s = new String(buffer);
            output.append(s);
        } while (read == BUFFER_SIZE);

        return output.toString();
    }
374648
public static void main(String[] args) throws Exception {
		File[] fs = new File("./bin").listFiles();
		//		File[] fs = new File("../testdata-groovy/bin").listFiles();
		//		File[] fs = new File("/Users/aclement/grailsreload/foo/target/classes").listFiles();

		checkThemAll(fs);
		System.out.println("total=" + total / 1000000d);
	}
730085
public void execute() throws BuildException
   {
      if (file == null)
         throw new BuildException("File not defined");

      if (!file.exists())
         throw new BuildException("File doesn't exists: " + file);

      try
      {
         Boolean result = null;
         if (isLocal())
         {
            Object value = executeCommand("local-undeploy", new Serializable[] {file.toURI().toURL()});

            if (value instanceof Boolean)
            {
               result = (Boolean)value;
            }
            else
            {
               throw (Throwable)value;
            }
         }
         else
         {
            Object value = executeCommand("remote-undeploy", new Serializable[] {file.getName()});

            if (value instanceof Boolean)
            {
               result = (Boolean)value;
            }
            else
            {
               throw (Throwable)value;
            }
         }

         if (result.booleanValue())
         {
            log("Undeployed: " + file.getName());
         }
         else
         {
            log(file.getName() + " wasn't undeployed");
         }
      }
      catch (Throwable t)
      {
         throw new BuildException("Unable to undeploy to " + getHost() + ":" + getPort() + " (" + t.getMessage() + ")",
                                  t);
      }
   }
215471
private void recordRunResults(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
                                  @Nonnull TaskListener listener, List<String> mergedResultNames,
                                  List<String> fileSystemResultNames) throws InterruptedException, IOException {


        for (String resultFile : mergedResultNames) {
            JUnitResultArchiver jUnitResultArchiver = new JUnitResultArchiver(resultFile);
            jUnitResultArchiver.setKeepLongStdio(true);
            jUnitResultArchiver.setAllowEmptyResults(true);
            jUnitResultArchiver.perform(build, workspace, launcher, listener);
        }

        final TestResultAction tempAction = build.getAction(TestResultAction.class);
        if (tempAction == null || tempAction.getResult() == null) {
            listener.getLogger().println("RunResultRecorder: didn't find any test results to record");
            return;
        }

        TestResult result = tempAction.getResult();


        try {
            archiveTestsReport(build, listener, fileSystemResultNames, result, workspace);
        } catch (ParserConfigurationException | SAXException e) {
            listener.error(ARCHIVING_TEST_REPORTS_FAILED_DUE_TO_XML_PARSING_ERROR + e);
        }

        if ((runReportList != null) && !(runReportList.isEmpty())) {
            LrJobResults jobDataSet = null;
            try {
                jobDataSet = buildJobDataset(listener);
            } catch (ParserConfigurationException | SAXException e) {
                listener.error(ARCHIVING_TEST_REPORTS_FAILED_DUE_TO_XML_PARSING_ERROR + e);
            }

            if ((jobDataSet != null && !jobDataSet.getLrScenarioResults().isEmpty())) {
                PerformanceJobReportAction performanceJobReportAction = build.getAction(PerformanceJobReportAction.class);
                if (performanceJobReportAction != null) {
                    performanceJobReportAction.mergeResults(jobDataSet);
                } else {
                    performanceJobReportAction = new PerformanceJobReportAction(build, jobDataSet);
                }
                build.replaceAction(performanceJobReportAction);
            }
        }
        publishLrReports(build);
    }
793780
public void execute() throws BuildException {
        checkParameters();
        resetFileLists();
        loadRegisteredScriptExtensions();

        if (javac != null) jointCompilation = true;

        // scan source directories and dest directory to build up
        // compile lists
        String[] list = src.list();
        for (String filename : list) {
            File file = getProject().resolveFile(filename);
            if (!file.exists()) {
                throw new BuildException("srcdir \"" + file.getPath() + "\" does not exist!", getLocation());
            }
            DirectoryScanner ds = this.getDirectoryScanner(file);
            String[] files = ds.getIncludedFiles();
            scanDir(file, destDir != null ? destDir : file, files);
        }

        compile();
        if (updatedProperty != null
                && taskSuccess
                && compileList.length != 0) {
            getProject().setNewProperty(updatedProperty, "true");
        }
    }
252590
public static JavaRDD<LabeledPoint> fromBinary(JavaPairRDD<String, PortableDataStream> binaryFiles,
                    final RecordReader reader) {
        JavaRDD<Collection<Writable>> records =
                        binaryFiles.map(new Function<Tuple2<String, PortableDataStream>, Collection<Writable>>() {
                            @Override
                            public Collection<Writable> call(
                                            Tuple2<String, PortableDataStream> stringPortableDataStreamTuple2)
                                            throws Exception {
                                reader.initialize(new InputStreamInputSplit(stringPortableDataStreamTuple2._2().open(),
                                                stringPortableDataStreamTuple2._1()));
                                return reader.next();
                            }
                        });

        JavaRDD<LabeledPoint> ret = records.map(new Function<Collection<Writable>, LabeledPoint>() {
            @Override
            public LabeledPoint call(Collection<Writable> writables) throws Exception {
                return pointOf(writables);
            }
        });
        return ret;
    }
357256
public static void main(String[] args) throws Exception {

		// Checking input parameters
		final ParameterTool params = ParameterTool.fromArgs(args);

		// set up input for the stream of integer pairs

		// obtain execution environment and set setBufferTimeout to 1 to enable
		// continuous flushing of the output buffers (lowest latency)
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment()
				.setBufferTimeout(1);

		// make parameters available in the web interface
		env.getConfig().setGlobalJobParameters(params);

		// create input stream of integer pairs
		DataStream<Tuple2<Integer, Integer>> inputStream;
		if (params.has("input")) {
			inputStream = env.readTextFile(params.get("input")).map(new FibonacciInputMap());
		} else {
			System.out.println("Executing Iterate example with default input data set.");
			System.out.println("Use --input to specify file input.");
			inputStream = env.addSource(new RandomFibonacciSource());
		}

		// create an iterative data stream from the input with 5 second timeout
		IterativeStream<Tuple5<Integer, Integer, Integer, Integer, Integer>> it = inputStream.map(new InputMap())
				.iterate(5000);

		// apply the step function to get the next Fibonacci number
		// increment the counter and split the output with the output selector
		SplitStream<Tuple5<Integer, Integer, Integer, Integer, Integer>> step = it.map(new Step())
				.split(new MySelector());

		// close the iteration by selecting the tuples that were directed to the
		// 'iterate' channel in the output selector
		it.closeWith(step.select("iterate"));

		// to produce the final output select the tuples directed to the
		// 'output' channel then get the input pairs that have the greatest iteration counter
		// on a 1 second sliding window
		DataStream<Tuple2<Tuple2<Integer, Integer>, Integer>> numbers = step.select("output")
				.map(new OutputMap());

		// emit results
		if (params.has("output")) {
			numbers.writeAsText(params.get("output"));
		} else {
			System.out.println("Printing result to stdout. Use --output to specify output path.");
			numbers.print();
		}

		// execute the program
		env.execute("Streaming Iteration Example");
	}
416059
protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
        BuilderFactory builderFactory = configuration.getBuilderFactory();
        AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
        constantsSummaryBuilder.build();
        AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
        serializedFormBuilder.build();
    }
427306
@Override
  public void execute() throws BuildException {
    //
    // if link type allowed objdir to be defaulted
    // provide it from outfile
    if (this._objDir == null) {
      if (this._outfile != null) {
        this._objDir = new File(this._outfile.getParent());
      } else {
        this._objDir = new File(".");
      }
    }

    //
    // if the object directory does not exist
    //
    if (!this._objDir.exists()) {
      throw new BuildException("Object directory does not exist");
    }
    final TargetHistoryTable objHistory = new TargetHistoryTable(this, this._objDir);

    //
    // get the first active version info
    //
    VersionInfo versionInfo = null;
    final Enumeration<VersionInfo> versionEnum = this.versionInfos.elements();
    while (versionEnum.hasMoreElements()) {
      versionInfo = versionEnum.nextElement();
      versionInfo = versionInfo.merge();
      if (versionInfo.isActive()) {
        break;
      } else {
        versionInfo = null;
      }
    }

    //
    // determine the eventual linker configuration
    // (may be null) and collect any explicit
    // object files or libraries
    final Vector<File> objectFiles = new Vector<>();
    final Vector<File> sysObjectFiles = new Vector<>();
    final LinkerConfiguration linkerConfig = collectExplicitObjectFiles(objectFiles, sysObjectFiles, versionInfo);

    //
    // Assemble hashtable of all files
    // that we know how to compile (keyed by output file name)
    //
    final Map<String, TargetInfo> targets = getTargets(linkerConfig, objectFiles, versionInfo, this._outfile);
    TargetInfo linkTarget = null;
    //
    // if output file is not specified,
    // then skip link step
    //
    if (this._outfile != null) {
      linkTarget = getLinkTarget(linkerConfig, objectFiles, sysObjectFiles, targets, versionInfo);
    }

    if (this.projects.size() > 0) {
      final List<File> files = new ArrayList<>();
      final ProjectFileCollector matcher = new ProjectFileCollector(files);
      for (int i = 0; i < this._compilers.size(); i++) {
    	  final CompilerDef currentCompilerDef = this._compilers.elementAt(i);
    	  if (currentCompilerDef.isActive() && currentCompilerDef.hasFileSets()) {
    		  currentCompilerDef.visitFiles(matcher);
    	  }
      }
      this.compilerDef.visitFiles(matcher);

      final Enumeration<ProjectDef> iter = this.projects.elements();
      while (iter.hasMoreElements()) {
        final ProjectDef projectDef = iter.nextElement();
        if (projectDef.isActive()) {
          projectDef.execute(this, files, targets, linkTarget);
        }
      }
    }
    if (this.projectsOnly) {
      return;
    }

    //
    // mark targets that don't have a history record or
    // whose source last modification time is not
    // the same as the history to be rebuilt
    //
    objHistory.markForRebuild(targets);
    final CCTaskProgressMonitor monitor = new CCTaskProgressMonitor(objHistory, versionInfo);
    //
    // check for changed include files
    //
    final int rebuildCount = checkForChangedIncludeFiles(targets);
    if (rebuildCount > 0) {
      BuildException compileException = null;
      //
      // compile all targets with getRebuild() == true
      //
      final Map<CompilerConfiguration, Vector<TargetInfo>> targetsByConfig = getTargetsToBuildByConfiguration(targets);
      //
      // build array containing Vectors with precompiled generation
      // steps going first
      //
      final ArrayList<Vector<TargetInfo>> targetVectorsPreComp = new ArrayList<>();
      final ArrayList<Vector<TargetInfo>> targetVectors = new ArrayList<>();

      int index = 0;
      for (final Map.Entry<CompilerConfiguration, Vector<TargetInfo>> targetsForConfig : targetsByConfig.entrySet()) {
        //
        // get the configuration from the first entry
        //
        final CompilerConfiguration config = targetsForConfig.getKey();
        if (config.isPrecompileGeneration()) {
          targetVectorsPreComp.add(targetsForConfig.getValue());
        } else {
          targetVectors.add(targetsForConfig.getValue());
        }
      }

      // BEGINFREEHEP
      final Progress progress = new Progress(getObjdir(), rebuildCount);
      progress.start();
      // ENDFREEHEP

      compileException = runTargetPool(monitor, compileException, targetVectorsPreComp);
      if (compileException == null || this.relentless)
        compileException = runTargetPool(monitor, compileException, targetVectors);

      // BEGINFREEHEP
      progress.exit();
      try {
        progress.join();
      } catch (final InterruptedException ex) {
      }
      // ENDFREEHEP

      //
      // save the details of the object file compilation
      // settings to disk for dependency analysis
      //
      try {
        objHistory.commit();
      } catch (final IOException ex) {
        this.log("Error writing history.xml: " + ex.toString());
      }
      //
      // if we threw a compile exception and
      // didn't throw it at the time because
      // we were relentless then
      // save the history and
      // throw the exception
      //
      if (compileException != null) {
        if (this.failOnError) {
          throw compileException;
        } else {
          log(compileException.getMessage(), Project.MSG_ERR);
          return;
        }
      }
    }
    //
    // if the dependency tree was not fully
    // evaluated, then throw an exception
    // since we really didn't do what we
    // should have done
    //
    //
    if (this.dependencyDepth >= 0) {
      throw new BuildException("All files at depth " + Integer.toString(this.dependencyDepth)
          + " from changes successfully compiled.\n"
          + "Remove or change dependencyDepth to -1 to perform full compilation.");
    }
    //
    // if no link target then
    // commit the history for the object files
    // and leave the task
    if (linkTarget != null) {
      //
      // get the history for the link target (may be the same
      // as the object history)
      final TargetHistoryTable linkHistory = getLinkHistory(objHistory);
      //
      // see if it needs to be rebuilt
      //
      linkHistory.markForRebuild(linkTarget);
      //
      // if it needs to be rebuilt, rebuild it
      //
      final File output = linkTarget.getOutput();
      if (linkTarget.getRebuild()) {
        final LinkerConfiguration linkConfig = (LinkerConfiguration) linkTarget.getConfiguration();
        // BEGINFREEHEP
        log("Linking...");
        log("Starting link {" + linkConfig.getIdentifier() + "}");
        // ENDFREEHEP
        if (this.failOnError) {
          linkConfig.link(this, linkTarget);
        } else {
          try {
            linkConfig.link(this, linkTarget);
          } catch (final BuildException ex) {
            log(ex.getMessage(), Project.MSG_ERR);
            return;
          }
        }
        if (this.outputFileProperty != null) {
          getProject().setProperty(this.outputFileProperty, output.getAbsolutePath());
        }
        linkHistory.update(linkTarget);
        try {
          linkHistory.commit();
        } catch (final IOException ex) {
          log("Error writing link history.xml: " + ex.toString());
        }
      } else {
        if (this.outputFileProperty != null) {
          getProject().setProperty(this.outputFileProperty, output.getAbsolutePath());
        }
      }

      // If sharedObjectName was specified, add the shared object to an archive, then delete the shared object.
      if (sharedObjectName != null && !sharedObjectName.isEmpty()) {
        File workingDirectory = new File(this._outfile.getParent());
        String[] archiveCommand = new String[4];
        archiveCommand[0] = "ar";
        archiveCommand[1] = "r";
        archiveCommand[2] = linkerConfig.getOutputFileNames(this._outfile.getName(), versionInfo)[0];
        archiveCommand[3] = sharedObjectName;
        CUtil.runCommand(this, workingDirectory, archiveCommand, false, null);

        String[] removeCommand = new String[2];
        removeCommand[0] = "rm";
        removeCommand[1] = sharedObjectName;
        CUtil.runCommand(this, workingDirectory, removeCommand, false, null);
      }
    }
  }
970902
public void execute() throws BuildException {
        log.debug("execute()");

        command = command.trim();

        if (srcFile == null && command.length() == 0 && filesets.isEmpty()) {
            throw new BuildException("Source file does not exist!", getLocation());
        }

        if (srcFile != null && !srcFile.exists()) {
            throw new BuildException("Source file does not exist!", getLocation());
        }

        // TODO: any of this used?
        // deal with the filesets
        for (int i = 0; i < filesets.size(); i++) {
            FileSet fs = filesets.elementAt(i);
            DirectoryScanner ds = fs.getDirectoryScanner(getProject());
            File srcDir = fs.getDir(getProject());
            String[] srcFiles = ds.getIncludedFiles();
        }

        try {
            PrintStream out = System.out;
            try {
                if (output != null) {
                    log.verbose("Opening PrintStream to output file " + output);
                    out = new PrintStream(
                            new BufferedOutputStream(
                                    new FileOutputStream(output.getAbsolutePath(), append)));
                }

                // if there are no groovy statements between the enclosing Groovy tags
                // then read groovy statements in from a text file using the src attribute
                if (command == null || command.trim().length() == 0) {
                    createClasspath().add(new Path(getProject(), srcFile.getParentFile().getCanonicalPath()));
                    command = getText(new BufferedReader(new FileReader(srcFile)));
                }

                if (command != null) {
                    execGroovy(command, out);
                } else {
                    throw new BuildException("Source file does not exist!", getLocation());
                }

            } finally {
                if (out != null && out != System.out) {
                    out.close();
                }
            }
        } catch (IOException e) {
            throw new BuildException(e, getLocation());
        }

        log.verbose("statements executed successfully");
    }
1092165
@NonNull
    public CrashReportData createCrashData(@NonNull final ReportBuilder builder) {
        final ExecutorService executorService = config.parallel() ? Executors.newCachedThreadPool() : Executors.newSingleThreadExecutor();
        final CrashReportData crashReportData = new CrashReportData();
        final List<Future<?>> futures = new ArrayList<>();
        for (final Collector collector : collectors) {
            futures.add(executorService.submit(() -> {
                //catch absolutely everything possible here so no collector obstructs the others
                try {
                    if(ACRA.DEV_LOGGING)ACRA.log.d(LOG_TAG, "Calling collector " + collector.getClass().getName());
                    collector.collect(context, config, builder, crashReportData);
                    if(ACRA.DEV_LOGGING)ACRA.log.d(LOG_TAG, "Collector " + collector.getClass().getName() + " completed");
                }catch (CollectorException e){
                    ACRA.log.w(LOG_TAG, e);
                }catch (Exception t) {
                    ACRA.log.e(LOG_TAG, "Error in collector " + collector.getClass().getSimpleName(), t);
                }
            }));
        }
        for (Future<?> future : futures) {
            while (!future.isDone()) {
                try {
                    future.get();
                } catch (InterruptedException ignored) {
                } catch (ExecutionException e) {
                    break;
                }
            }
        }
        return crashReportData;
    }
995496
protected static final void write(StringBuilder builder, Tree node, Tree zeroIndexes) {
		int startIndex = zeroIndexes == null ? 1 : Integer.MIN_VALUE;
		for (Tree child : node) {
			if (child.isStructure()) {
				write(builder, child, zeroIndexes);
			} else {
				if (startIndex == Integer.MIN_VALUE) {
					startIndex = zeroIndexes.get(node.getName(), 1);
				}
				append(builder, child.getPath(startIndex), String.valueOf(child.asString()));
			}
		}
	}
146645
public void compileBatch(String []files)
    throws IOException, ClassNotFoundException
  {
    if (_compileParent) {
      try {
        if (_loader instanceof Make)
          ((Make) _loader).make();
      } catch (Exception e) {
        throw new IOException(e);
      }
    }

    if (files.length == 0)
      return;

    // only batch a number of files at a time

    int batchCount = _maxBatch;
    if (batchCount < 0)
      batchCount = Integer.MAX_VALUE / 2;
    else if (batchCount == 0)
      batchCount = 1;

    IOException exn = null;

    ArrayList<String> uniqueFiles = new ArrayList<String>();
    for (int i = 0; i < files.length; i++) {
      if (! uniqueFiles.contains(files[i]))
        uniqueFiles.add(files[i]);
    }
    files = new String[uniqueFiles.size()];
    uniqueFiles.toArray(files);

    LineMap lineMap = null;
    
    _compilerService.compile(this, files, lineMap);

    /*
    synchronized (LOCK) {
      for (int i = 0; i < files.length; i += batchCount) {
        int len = files.length - i;

        len = Math.min(len, batchCount);

        String []batchFiles = new String[len];

        System.arraycopy(files, i, batchFiles, 0, len);

        Arrays.sort(batchFiles);

        try {
          compileInt(batchFiles, null);
        } catch (IOException e) {
          if (exn == null)
            exn = e;
          else
            log.log(Level.WARNING, e.toString(), e);
        }
      }
    }

    if (exn != null)
      throw exn;
      */
  }
1338330
public function processClones($clones, Project $project, $useFile = false, $outFile = null)
    {
        if (!$useFile || empty($outFile)) {
            throw new BuildException('Output filename required for this formatter');
        }

        if (get_class($clones) == 'PHPCPD_CloneMap') {
            $logger = new PHPCPD_Log_XML_PMD($outFile);
        } else {
            $logger = new \SebastianBergmann\PHPCPD\Log\PMD($outFile);
        }

        $logger->processClones($clones);
    }