<commit_before>package com.xorlev.gatekeeper;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
import com.xorlev.gatekeeper.AppConfig;
import com.xorlev.gatekeeper.data.ConfigContext;

import java.io.*;

public class ConfigWriter {
    private final Mustache mustache;
    private Writer writer = new OutputStreamWriter(System.out);

    public ConfigWriter(Writer writer) {
        MustacheFactory mf = new DefaultMustacheFactory();
        Reader reader = null;
        try {
            reader = new FileReader(new File(AppConfig.getString("nginx.template-file")));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        this.mustache = mf.compile(reader, "nginx_conf");
        this.writer = writer;
    }

    public void writeConfig(ConfigContext configContext) throws IOException {
        System.out.println(configContext);
        String filename = AppConfig.getString("nginx.config-file");
        writer = new FileWriter(filename);
        mustache.execute(writer, configContext).flush();
    }
}<commit_msg>Trying classpath for nginx config if it can't be found<commit_after>package com.xorlev.gatekeeper;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
import com.xorlev.gatekeeper.AppConfig;
import com.xorlev.gatekeeper.data.ConfigContext;

import java.io.*;

public class ConfigWriter {
    private final Mustache mustache;
    private Writer writer = new OutputStreamWriter(System.out);

    public ConfigWriter(Writer writer) {
        MustacheFactory mf = new DefaultMustacheFactory();
        Reader reader = null;
        try {
            reader = new FileReader(new File(AppConfig.getString("nginx.template-file")));
        } catch (FileNotFoundException e) {
            try {
                InputStream is = this.getClass().getResourceAsStream("nginx.conf.mustache");

                if (is == null) throw e;

                reader = new InputStreamReader(is);
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            }
        }

        this.mustache = mf.compile(reader, "nginx_conf");
        this.writer = writer;
    }

    public void writeConfig(ConfigContext configContext) throws IOException {
        System.out.println(configContext);
        String filename = AppConfig.getString("nginx.config-file");
        writer = new FileWriter(filename);
        mustache.execute(writer, configContext).flush();
    }
}
{'fraction_non_alphanumeric': 0.09744956223829464, 'fraction_numerical': 0.0007613247049866769, 'mean_word_length': 3.080745341614907, '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': '6435381', 'n_tokens_mistral': 715, 'n_tokens_neox': 693, 'n_words': 154}