<commit_before>package com.redhat.rhevm.api.powershell;

import java.io.InputStream;
import java.util.Scanner;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PowerShellCmd
{
	private final Log log = LogFactory.getLog(this.getClass());

	private String script;

	public PowerShellCmd(String script) {
		this.script = script;
	}

	private String stdout, stderr;

	public int run() {
		log.debug("Running '" + script + "'");

		ProcessBuilder pb = new ProcessBuilder("powershell", "-command", "-");

		Process p;

		try {
			p = pb.start();
		} catch	(java.io.IOException ex) {
			throw new PowerShellException("Launching powershell failed", ex);
		}

		try {
			p.getOutputStream().write(script.getBytes());
			p.getOutputStream().close();
		} catch (java.io.IOException ex) {
			throw new PowerShellException("Writing to powershell process failed", ex);
		}

		StreamReader stdoutThread = new StreamReader(p.getInputStream());
		StreamReader stderrThread = new StreamReader(p.getErrorStream());

		stdoutThread.start();
		stderrThread.start();

		int exitstatus;

		try {
			exitstatus = p.waitFor();
		} catch	(java.lang.InterruptedException ex) {
			// FIXME: error handling
			throw new PowerShellException("FIXME", ex);
		}

		try {
			stdoutThread.join();
			stderrThread.join();
		} catch (java.lang.InterruptedException ex) {
			// FIXME: error handling
			throw new PowerShellException("FIXME", ex);
		}

		stdout = stdoutThread.getOutput();
		stderr = stderrThread.getOutput();

		return exitstatus;
	}

	public String getStdOut() {
		return this.stdout;
	}

	public String getStdErr() {
		return this.stderr;
	}

	private class StreamReader extends Thread {
		private InputStream is;

		public StreamReader(InputStream is) {
			this.is = is;
		}

		private String output = new String();
		public String getOutput() {
			return output;
		}

		@Override
		public void run() {
			Scanner sc = new Scanner(is);
			while (sc.hasNext()) {
				output += sc.nextLine() + "\n";
			}
		}
	}
}<commit_msg>PowerShellCmd: use StringBuilder for output buffering<commit_after>package com.redhat.rhevm.api.powershell;

import java.io.InputStream;
import java.util.Scanner;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PowerShellCmd
{
	private final Log log = LogFactory.getLog(this.getClass());

	private String script;

	public PowerShellCmd(String script) {
		this.script = script;
	}

	private String stdout, stderr;

	public int run() {
		log.debug("Running '" + script + "'");

		ProcessBuilder pb = new ProcessBuilder("powershell", "-command", "-");

		Process p;

		try {
			p = pb.start();
		} catch	(java.io.IOException ex) {
			throw new PowerShellException("Launching powershell failed", ex);
		}

		try {
			p.getOutputStream().write(script.getBytes());
			p.getOutputStream().close();
		} catch (java.io.IOException ex) {
			throw new PowerShellException("Writing to powershell process failed", ex);
		}

		StreamReader stdoutThread = new StreamReader(p.getInputStream());
		StreamReader stderrThread = new StreamReader(p.getErrorStream());

		stdoutThread.start();
		stderrThread.start();

		int exitstatus;

		try {
			exitstatus = p.waitFor();
		} catch	(java.lang.InterruptedException ex) {
			// FIXME: error handling
			throw new PowerShellException("FIXME", ex);
		}

		try {
			stdoutThread.join();
			stderrThread.join();
		} catch (java.lang.InterruptedException ex) {
			// FIXME: error handling
			throw new PowerShellException("FIXME", ex);
		}

		stdout = stdoutThread.getOutput();
		stderr = stderrThread.getOutput();

		return exitstatus;
	}

	public String getStdOut() {
		return this.stdout;
	}

	public String getStdErr() {
		return this.stderr;
	}

	private class StreamReader extends Thread {
		private InputStream is;

		public StreamReader(InputStream is) {
			this.is = is;
		}

		private StringBuilder outputBuffer = new StringBuilder();
		public String getOutput() {
			return outputBuffer.toString();
		}

		@Override
		public void run() {
			Scanner sc = new Scanner(is);
			while (sc.hasNext()) {
				outputBuffer.append(sc.nextLine() + "\n");
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.12642857142857142, 'fraction_numerical': 0.0, 'mean_word_length': 3.839861751152074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5109432', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1291, 'n_words': 320}