<commit_before>/*
 * 
 * Copyright 2001-2004 The Ant-Contrib project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
// BEGINFREEHEP, fully replaced with a runner with threads
package com.github.maven_nar.cpptasks.compiler;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Vector;

import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
/**
 * Implements ExecuteStreamHandler to capture the output of a Execute to an
 * array of strings
 * 
 * @author <NAME>
 */
public class CaptureStreamHandler implements ExecuteStreamHandler {

	private String[] stderr;
	private String[] stdout;

	/**
	 * Runs an executable and captures the output in a String array
	 * 
	 * @param cmdline
	 *            command line arguments
	 * @return output of process
	 */
	public static String[] run(String[] cmdline) {
		CaptureStreamHandler handler = new CaptureStreamHandler();
		Execute exec = new Execute(handler);
		exec.setCommandline(cmdline);
		try {
			int status = exec.execute();
		} catch (IOException ex) {
		}
		return handler.getOutput() != null ? handler.getOutput() : new String[0];
	}

	private InputStream processErrorStream;

	private InputStream processOutputStream;

	public CaptureStreamHandler() {
	}

	/**
	 * Gets the output of the execution. If standard error is not empty,
	 * it is returned; otherwise, standard output is returned.
	 */
	public String[] getOutput() {
		return stderr.length > 0 ? stderr : stdout;
	}

	/** Gets the output of the execution's standard error stream. */
	public String[] getStderr() {
		return stderr;
	}

	/** Gets the output of the execution's standard output stream. */
	public String[] getStdout() {
		return stdout;
	}
<commit_msg>CaptureStreamHandler: add execute static method<commit_after>/*
 * 
 * Copyright 2001-2004 The Ant-Contrib project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
// BEGINFREEHEP, fully replaced with a runner with threads
package com.github.maven_nar.cpptasks.compiler;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Vector;

import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
/**
 * Implements ExecuteStreamHandler to capture the output of a Execute to an
 * array of strings
 * 
 * @author <NAME>
 */
public class CaptureStreamHandler implements ExecuteStreamHandler {

	private String[] stderr;
	private String[] stdout;

	/**
	 * Runs an executable and captures the output in a String array
	 * 
	 * @param cmdline
	 *            command line arguments
	 * @return output of process
	 * @see CaptureStreamHandler#getOutput()
	 */
	public static String[] run(String[] cmdline) {
		CaptureStreamHandler handler = execute(cmdline);
		return handler.getOutput() != null ? handler.getOutput() : new String[0];
	}

	/**
	 * Executes the given command, capturing the output using a newly allocated
	 * {@link CaptureStreamHandler}, which is then returned.
	 * <p>
	 * In contrast to {@link #run(String[])}, this method allows both the
	 * standard error and standard output streams to be inspected after execution
	 * (via the {@link #getStderr()} and {@link #getStdout()} methods,
	 * respectively).
	 * </p>
	 * 
	 * @param cmdline
	 *            command line arguments
	 * @return The {@link CaptureStreamHandler} used to capture the output.
	 */
	public static CaptureStreamHandler execute(String[] cmdline) {
		CaptureStreamHandler handler = new CaptureStreamHandler();
		Execute exec = new Execute(handler);
		exec.setCommandline(cmdline);
		try {
			int status = exec.execute();
		} catch (IOException ex) {
		}
		return handler;
	}

	private InputStream processErrorStream;

	private InputStream processOutputStream;

	public CaptureStreamHandler() {
	}

	/**
	 * Gets the output of the execution. If standard error is not empty,
	 * it is returned; otherwise, standard output is returned.
	 */
	public String[] getOutput() {
		return stderr.length > 0 ? stderr : stdout;
	}

	/** Gets the output of the execution's standard error stream. */
	public String[] getStderr() {
		return stderr;
	}

	/** Gets the output of the execution's standard output stream. */
	public String[] getStdout() {
		return stdout;
	}

{'fraction_non_alphanumeric': 0.0930147729345249, 'fraction_numerical': 0.005106693416013132, 'mean_word_length': 3.8617021276595747, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '378955', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1484, 'n_words': 575}