<commit_before>package fi.helsinki.cs.okkopa.shared;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

/**
 * Manages and reads XML files.
 */
@Component
public class Settings extends Properties {

    private static final Logger LOGGER = Logger.getLogger(Settings.class.getName());

    public Settings() throws IOException {
        String envVar = "OKKOPA_SETTINGS_FILEPATH";
        String filePath = System.getenv(envVar);
        if (filePath == null) {
            LOGGER.warn(envVar + " environment variable not set, trying to find settings.xml in program folder.");
            filePath = "settings.xml";
        }
        Properties props = readSettingXML(filePath);
        this.putAll(props);
    }

    /**
     *
     * @param fileName to where xml-file is.
     * @throws IOException
     */
    public Settings(String fileName) throws IOException {
        Properties props = readSettingXML(fileName);
        this.putAll(props);
    }

    private Properties readSettingXML(String fileName) throws IOException {
        Properties currentProps = new Properties();

        try {
            InputStream currentStream = getClass().getResourceAsStream("/" + fileName);
            currentProps.loadFromXML(currentStream);
            currentStream.close();
            return currentProps;
        } catch (Exception e) {
            FileInputStream fis = new FileInputStream(fileName);
            currentProps.loadFromXML(fis);
            fis.close();
            return currentProps;
        }
    }
}
<commit_msg>muutettu exception tekstejä kun settareita ei löydy.<commit_after>package fi.helsinki.cs.okkopa.shared;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

/**
 * Manages and reads XML files.
 */
@Component
public class Settings extends Properties {

    private static final Logger LOGGER = Logger.getLogger(Settings.class.getName());

    public Settings() throws IOException {
        String envVar = "OKKOPA_SETTINGS_FILEPATH";
        String filePath = System.getenv(envVar);
        Properties props;
        if (filePath == null) {
            LOGGER.warn(envVar + " environment variable not set, trying to find settings.xml in program folder.");
            filePath = "settings.xml";
            try {
                props = readSettingXML(filePath);
            } catch(IOException ex) {
                throw new IOException("Settings file could not be found using environment variable: "+envVar+". Value of "+envVar+" was set to: "+filePath+
                                      ". Make sure it points to your xml settings file.");
            }
        } else {
            try {
                props = readSettingXML(filePath);
            } catch(IOException ex) {
                throw new IOException("Settings file could not be found. Environment variable: "+envVar+" was not set."+
                                      "Make sure it points to your xml settings file.");
            }
        }
        this.putAll(props);
    }

    /**
     *
     * @param fileName to where xml-file is.
     * @throws IOException
     */
    public Settings(String fileName) throws IOException {
        Properties props = readSettingXML(fileName);
        this.putAll(props);
    }

    private Properties readSettingXML(String fileName) throws IOException {
        Properties currentProps = new Properties();

        try {
            InputStream currentStream = getClass().getResourceAsStream("/" + fileName);
            currentProps.loadFromXML(currentStream);
            currentStream.close();
            return currentProps;
        } catch (Exception e) {
            FileInputStream fis = new FileInputStream(fileName);
            currentProps.loadFromXML(fis);
            fis.close();
            return currentProps;
        }
    }
}

{'fraction_non_alphanumeric': 0.09237536656891496, 'fraction_numerical': 0.0004887585532746823, 'mean_word_length': 2.3249390739236393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6203716', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1024, 'n_words': 285}