diff --git a/src/main/java/de/fabianonline/telegram_backup/exporter/HTMLExporter.java b/src/main/java/de/fabianonline/telegram_backup/exporter/HTMLExporter.java index 1d59645..45a697d 100644 --- a/src/main/java/de/fabianonline/telegram_backup/exporter/HTMLExporter.java +++ b/src/main/java/de/fabianonline/telegram_backup/exporter/HTMLExporter.java @@ -87,7 +87,7 @@ public class HTMLExporter { MustacheFactory mf = new DefaultMustacheFactory(); Mustache mustache = mf.compile("templates/html/index.mustache"); - OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(base + "index.html"), Charset.forName("UTF-8").newEncoder()); + OutputStreamWriter w = getWriter(base + "index.html"); mustache.execute(w, scope); w.close(); @@ -106,7 +106,7 @@ public class HTMLExporter { scope.putAll(db.getMessageTypesWithCount(d)); scope.putAll(db.getMessageMediaTypesWithCount(d)); - w = new OutputStreamWriter(new FileOutputStream(base + "dialogs" + File.separatorChar + "user_" + d.id + ".html"), Charset.forName("UTF-8").newEncoder()); + w = getWriter(base + "dialogs" + File.separatorChar + "user_" + d.id + ".html"); mustache.execute(w, scope); w.close(); } @@ -124,7 +124,7 @@ public class HTMLExporter { scope.putAll(db.getMessageTypesWithCount(c)); scope.putAll(db.getMessageMediaTypesWithCount(c)); - w = new OutputStreamWriter(new FileOutputStream(base + "dialogs" + File.separatorChar + "chat_" + c.id + ".html"), Charset.forName("UTF-8").newEncoder()); + w = getWriter(base + "dialogs" + File.separatorChar + "chat_" + c.id + ".html"); mustache.execute(w, scope); w.close(); } @@ -139,6 +139,11 @@ public class HTMLExporter { throw new RuntimeException("Exception above!"); } } + + private OutputStreamWriter getWriter(String filename) { + logger.trace("Creating writer for file {}", filename); + return new OutputStreamWriter(new FileOutputStream(filename), Charset.forName("UTF-8").newEncoder()); + } private String intArrayToString(int[][] data) { StringBuilder sb = new StringBuilder();