| 1 | package de.aikiit.mailversendala.template; | |
| 2 | ||
| 3 | import com.google.common.base.Charsets; | |
| 4 | import com.google.common.io.CharStreams; | |
| 5 | import de.aikiit.mailversendala.MailConfig; | |
| 6 | ||
| 7 | import java.io.IOException; | |
| 8 | import java.io.InputStream; | |
| 9 | import java.io.InputStreamReader; | |
| 10 | import java.nio.charset.StandardCharsets; | |
| 11 | import java.nio.file.Files; | |
| 12 | import java.nio.file.Path; | |
| 13 | import java.nio.file.Paths; | |
| 14 | ||
| 15 | /** | |
| 16 |  * Template class that is based on a file, whose contents is replaced in a structured manner. | |
| 17 |  */ | |
| 18 | public class FileMailTemplate implements MailTemplate { | |
| 19 |     private final String html; | |
| 20 |     private final String plaintext; | |
| 21 | ||
| 22 |     /** | |
| 23 |      * Read given input streams and populate internal mailing contents. | |
| 24 |      * @param html HTML-format contents. | |
| 25 |      * @param plaintext plain text-contents. | |
| 26 |      * @throws IOException in case of errors. | |
| 27 |      */ | |
| 28 |     public FileMailTemplate(InputStream html, InputStream plaintext) throws IOException { | |
| 29 |         this.html = CharStreams.toString(new InputStreamReader(html, Charsets.UTF_8)); | |
| 30 |         this.plaintext = CharStreams.toString(new InputStreamReader(plaintext, Charsets.UTF_8)); | |
| 31 |     } | |
| 32 | ||
| 33 |     /** | |
| 34 |      * Apply given configuration and generate internal mailing contents. | |
| 35 |      * @param config configuration parameters of the application. | |
| 36 |      * @throws IOException in case of errors. | |
| 37 |      */ | |
| 38 |     public FileMailTemplate(MailConfig config) throws IOException { | |
| 39 |         this.html = readInLanguage(Paths.get(config.getTemplatePath(), BASE_NAME_HTML)); | |
| 40 |         this.plaintext = readInLanguage(Paths.get(config.getTemplatePath(), BASE_NAME_PLAINTEXT)); | |
| 41 |     } | |
| 42 | ||
| 43 |     private static String readInLanguage(Path file) throws IOException { | |
| 44 | 1
1. readInLanguage : replaced return value with "" for de/aikiit/mailversendala/template/FileMailTemplate::readInLanguage → KILLED |         return Files.readString(file, StandardCharsets.UTF_8); | 
| 45 |     } | |
| 46 | ||
| 47 |     @Override | |
| 48 |     public String getHtml() { | |
| 49 | 1
1. getHtml : replaced return value with "" for de/aikiit/mailversendala/template/FileMailTemplate::getHtml → KILLED |         return html; | 
| 50 |     } | |
| 51 | ||
| 52 |     @Override | |
| 53 |     public String getPlaintext() { | |
| 54 | 1
1. getPlaintext : replaced return value with "" for de/aikiit/mailversendala/template/FileMailTemplate::getPlaintext → KILLED |         return plaintext; | 
| 55 |     } | |
| 56 | } | |
| Mutations | ||
| 44 | 1.1 | |
| 49 | 1.1 | |
| 54 | 1.1 |