<commit_before>package com.google.code.maven_replacer_plugin;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.List;

import com.google.code.maven_replacer_plugin.file.FileUtils;


public class Replacer {
	private final FileUtils fileUtils;
	private final TokenReplacer tokenReplacer;

	public Replacer(FileUtils fileUtils, TokenReplacer tokenReplacer) {
		this.fileUtils = fileUtils;
		this.tokenReplacer = tokenReplacer;
	}

	public void replace(List<ReplacerContext> contexts, boolean regex, String file,
			String outputFile, int regexFlags) throws IOException {
		String content = fileUtils.readFile(file);
		for (ReplacerContext context : contexts) {
			if (context.getToken() == null || context.getToken().trim().length() == 0) {
				throw new IllegalArgumentException("Token or token file required");
			}

			if (regex) {
				content = tokenReplacer.replaceRegex(content, context.getToken(), context.getValue(), regexFlags);
			} else {
				content = tokenReplacer.replaceNonRegex(content, context.getToken(), context.getValue());
			}
		}

		Writer writer = new OutputStreamWriter(new FileOutputStream(outputFile));
		writer.write(content);
		writer.close();
	}

	public FileUtils getFileUtils() {
		return fileUtils;
	}

	public TokenReplacer getTokenReplacer() {
		return tokenReplacer;
	}
}<commit_msg>need to ensure outputfile can be created<commit_after>package com.google.code.maven_replacer_plugin;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.List;

import com.google.code.maven_replacer_plugin.file.FileUtils;


public class Replacer {
	private final FileUtils fileUtils;
	private final TokenReplacer tokenReplacer;

	public Replacer(FileUtils fileUtils, TokenReplacer tokenReplacer) {
		this.fileUtils = fileUtils;
		this.tokenReplacer = tokenReplacer;
	}

	public void replace(List<ReplacerContext> contexts, boolean regex, String file,
			String outputFile, int regexFlags) throws IOException {
		String content = fileUtils.readFile(file);
		for (ReplacerContext context : contexts) {
			if (context.getToken() == null || context.getToken().trim().length() == 0) {
				throw new IllegalArgumentException("Token or token file required");
			}

			if (regex) {
				content = tokenReplacer.replaceRegex(content, context.getToken(), context.getValue(), regexFlags);
			} else {
				content = tokenReplacer.replaceNonRegex(content, context.getToken(), context.getValue());
			}
		}

		fileUtils.ensureFolderStructureExists(outputFile);
		Writer writer = new OutputStreamWriter(new FileOutputStream(outputFile));
		writer.write(content);
		writer.close();
	}

	public FileUtils getFileUtils() {
		return fileUtils;
	}

	public TokenReplacer getTokenReplacer() {
		return tokenReplacer;
	}
}
{'fraction_non_alphanumeric': 0.10325710325710326, 'fraction_numerical': 0.000693000693000693, 'mean_word_length': 5.235421166306695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6541005', 'n_tokens_mistral': 940, 'n_tokens_neox': 851, 'n_words': 199}