package com.epimorphics.registry.language.message;

import com.epimorphics.registry.language.MessagesProperties;
import com.epimorphics.util.EpiException;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.jena.atlas.lib.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

public class FileMessageManager implements MessageManager {
    private final Logger log = LoggerFactory.getLogger(FileMessageManager.class);
    private final Map<String, Messages> messagesByLang;

    public FileMessageManager() {
        this("/opt/ldregistry/config/language/messages");
    }

    FileMessageManager(String msgsLoc) {
        File msgDir = new File(msgsLoc);
        this.messagesByLang = getMessagesByLang(msgDir);
    }

    private Map<String, Messages> getMessagesByLang(File msgDir) {
        File[] msgFiles = msgDir.listFiles((FileFilter) new SuffixFileFilter("properties"));
        if (msgFiles == null) {
            log.warn("Messages directory does not exist: " + msgDir.getAbsolutePath());
            return new HashMap<>();
        }

        return Arrays.stream(msgFiles).map(msgFile -> {
            log.info("Configuring messages file at " + msgFile.getAbsolutePath());
            String lang = msgFile.getName().replace(".properties", "");
            try {
                Messages msgs = getMessages(lang, msgFile);
                return new Pair<>(lang, msgs);
            } catch (IOException ioe) {
                throw new EpiException("Unable to read message files.", ioe);
            }
        }).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
    }

    private Messages getMessages(String lang, File msgFile) throws IOException {
        Properties props = getProperties(msgFile);
        return new MessagesProperties(lang, props);
    }

    private Properties getProperties(File msgFile) throws IOException {
        try (FileReader reader = new FileReader(msgFile)) {
            Properties props = new Properties();
            props.load(reader);

            return props;
        }
    }

    @Override public Messages getMessages(String lang) {
        return messagesByLang.get(lang);
    }
}

@@ -318,20 +318,17 @@
 java.io.
-File
+*
 ;%0Aimport
@@ -337,76 +337,36 @@
 ava.
+n
 io.
-FileFilter;%0Aimport java.io.FileReader;%0Aimport java.io.IOException
+charset.StandardCharsets
 ;%0Aim
@@ -2097,54 +2097,141 @@
 ry (
-FileReader reader = new FileReader(msgFile)) %7B
+InputStream input = new FileInputStream(msgFile)) %7B%0A            Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8);
 %0A   

Change message file reader to use UTF-8