<commit_before>package de.aikiit.mailversendala.template;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import lombok.Data;
import org.assertj.core.util.Strings;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

@Data
public class FileMailTemplate implements MailTemplate {
    private Map<String, String> html = new HashMap<>();
    private Map<String, String> plaintext = new HashMap<>();

    public FileMailTemplate(InputStream html, InputStream plaintext, Map<String, String> parameters) throws IOException {
        // TODO 		try (BufferedReader br = Files.newBufferedReader(Paths.get(fileName))) { in a separate class
        this.html.put(MailTemplate.BACKUP_LANGUAGE, CharStreams.toString(new InputStreamReader(html, Charsets.UTF_8)));
        this.plaintext.put(MailTemplate.BACKUP_LANGUAGE, CharStreams.toString(new InputStreamReader(plaintext, Charsets.UTF_8)));
    }

    /*
    use MailTemplate.LANGUAGES

    public FileMailTemplate(File basePath, Map<String, String> parameters) {
        Paths.get(new File(basePath, MailTemplate.BASE_NAME_PLAINTEXT));
        Paths.get(new File(basePath, MailTemplate.BASE_NAME_HTML));
    }
*/
    @Override<commit_msg>Issue #13: Add File based constructor<commit_after>package de.aikiit.mailversendala.template;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import de.aikiit.mailversendala.MailConfig;
import lombok.Data;
import org.assertj.core.util.Strings;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

@Data
public class FileMailTemplate implements MailTemplate {
    private Map<String, String> html = new HashMap<>();
    private Map<String, String> plaintext = new HashMap<>();

    public FileMailTemplate(InputStream html, InputStream plaintext, Map<String, String> parameters) throws IOException {
        // TODO 		try (BufferedReader br = Files.newBufferedReader(Paths.get(fileName))) { in a separate class
        this.html.put(MailTemplate.BACKUP_LANGUAGE, CharStreams.toString(new InputStreamReader(html, Charsets.UTF_8)));
        this.plaintext.put(MailTemplate.BACKUP_LANGUAGE, CharStreams.toString(new InputStreamReader(plaintext, Charsets.UTF_8)));
    }

    public FileMailTemplate(MailConfig config) throws IOException {
        this.html.put(MailTemplate.BACKUP_LANGUAGE, readInLanguage(Paths.get(config.getTemplatePath(), MailTemplate.BASE_NAME_HTML)));
        this.plaintext.put(MailTemplate.BACKUP_LANGUAGE, readInLanguage(Paths.get(config.getTemplatePath(), MailTemplate.BASE_NAME_PLAINTEXT)));
    }

    private static String readInLanguage(Path file) throws IOException {
        return new String(Files.readAllBytes(file));
    }

    @Override
{'fraction_non_alphanumeric': 0.10535173342308987, 'fraction_numerical': 0.002019522046449007, 'mean_word_length': 5.040650406504065, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '419318', 'n_tokens_mistral': 881, 'n_tokens_neox': 872, 'n_words': 179}