<commit_before>package com.github.aureliano.achmed.command;

import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.Callable;

import com.github.aureliano.achmed.helper.StringHelper;

public class CommandRunner implements Callable<CommandResponse> {

	private List<String> command;
	private File workingDir;
	private boolean verbose;
	
	public CommandRunner(String command, String dir, boolean verbose) {
		this.command = Arrays.asList(command.split("\\s+"));
		this.workingDir = new File(dir);
		this.verbose = verbose;
	}
	
	public CommandResponse call() throws Exception {
		return this.execute();
	}
	
	public CommandResponse execute() {
		ProcessBuilder builder = new ProcessBuilder(this.command);
		builder.directory(this.workingDir);
		
		int exitStatus = Integer.parseInt("1" + this.command.size());
		Process process = null;
		CommandResponse response = new CommandResponse(StringHelper.join(this.command, " "));
		
		try {
			process = builder.start();
			response.withOutput(this.scanCommand(process));
			exitStatus = process.waitFor();
		} catch (Exception ex) {
			response.withError(this.readError(process));
		}
		
		return response.withExitStatusCode(exitStatus);
	}
	
	private String scanCommand(Process process) {
		return this.consumeStream(process.getInputStream(), this.verbose);
	}
	
	private String readError(Process process) {
		return this.consumeStream(process.getErrorStream(), true);
	}
	
	private String consumeStream(InputStream stream, boolean verbose) {
		Scanner scanner = new Scanner(stream);
		StringBuilder builder = new StringBuilder();
		
		while (scanner.hasNextLine()) {
			String line = scanner.nextLine();
			builder.append(line).append("\n");
			
			if (verbose) {
				System.out.println(line);
			}
		}
		
		if (builder.length() > 0) {
			builder.deleteCharAt(builder.length() - 1);
		}
		scanner.close();
		
		return builder.toString();
	}
}<commit_msg>Use buffered reader instead of scanner to read process stream.<commit_after>package com.github.aureliano.achmed.command;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;

import com.github.aureliano.achmed.exception.AchmedException;
import com.github.aureliano.achmed.helper.StringHelper;

public class CommandRunner implements Callable<CommandResponse> {

	private List<String> command;
	private File workingDir;
	private boolean verbose;
	
	public CommandRunner(String command, String dir, boolean verbose) {
		this.command = Arrays.asList(command.split("\\s+"));
		this.workingDir = new File(dir);
		this.verbose = verbose;
	}
	
	public CommandResponse call() throws Exception {
		return this.execute();
	}
	
	public CommandResponse execute() {
		ProcessBuilder builder = new ProcessBuilder(this.command);
		builder.directory(this.workingDir);
		
		int exitStatus = Integer.parseInt("1" + this.command.size());
		Process process = null;
		CommandResponse response = new CommandResponse(StringHelper.join(this.command, " "));
		
		try {
			process = builder.start();
			response.withOutput(this.scanCommand(process));
			
			exitStatus = process.waitFor();
		} catch (Exception ex) {
			response.withError(this.readError(process));
		}
		
		return response.withExitStatusCode(exitStatus);
	}
	
	private String scanCommand(Process process) {
		return this.consumeStream(process.getInputStream(), this.verbose);
	}
	
	private String readError(Process process) {
		return this.consumeStream(process.getErrorStream(), true);
	}
	
	private String consumeStream(InputStream stream, boolean verbose) {
		try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream))) {
			StringBuilder builder = new StringBuilder();
			
			String line = null;
			while ((line = bufferedReader.readLine()) != null) {
				builder.append(line).append("\n");
				
				if (verbose) {
					System.out.println(line);
				}
			}
			
			if (builder.length() > 0) {
				builder.deleteCharAt(builder.length() - 1);
			}
			
			return builder.toString();
		} catch (Exception ex) {
			throw new AchmedException(ex);
		}
	}
}
{'fraction_non_alphanumeric': 0.11916490734224724, 'fraction_numerical': 0.0014074595355383533, 'mean_word_length': 4.473684210526316, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6890036', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1219, 'n_words': 276}