<commit_before>package io.quarkus.undertow.websockets.deployment;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;

import org.jboss.logging.Logger;

import io.quarkus.deployment.devmode.HotReplacementContext;
import io.quarkus.deployment.devmode.HotReplacementSetup;
import io.quarkus.undertow.runtime.UndertowDeploymentRecorder;
import io.undertow.Handlers;
import io.undertow.predicate.Predicates;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ServletContainer;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;

public class WebsocketHotReloadSetup implements HotReplacementSetup {

    private static Logger logger = Logger.getLogger(WebsocketHotReloadSetup.class);

    static volatile String replacementPassword;

    @Override
    public void setupHotDeployment(HotReplacementContext hotReplacementContext) {
        // we can't use the typical ConfigProvider.getConfig() because the config infrastructure isn't setup at this point
        String password = System.getProperty(HotReplacementWebsocketEndpoint.QUARKUS_LIVE_RELOAD_PASSWORD);
        if (password == null || password.isEmpty()) {
            password = System.getenv(HotReplacementWebsocketEndpoint.QUARKUS_LIVE_RELOAD_PASSWORD_ENV);
        }

        if (password != null && !password.isEmpty()) {
            replacementPassword = password;
        } else {
            List<Path> resources = hotReplacementContext.getResourcesDir();
            if (!resources.isEmpty()) {
                //TODO: fix this
                File appConfig = resources.get(0).resolve("application.properties").toFile();
                if (appConfig.isFile()) {
                    try (InputStream pw = new FileInputStream(appConfig)) {
                        Properties p = new Properties();
                        p.load(pw);
                        replacementPassword = p.getProperty(HotReplacementWebsocketEndpoint.QUARKUS_LIVE_RELOAD_PASSWORD);
                    } catch (IOException e) {
                        logger.error("Failed to read application.properties", e);
                    }
                }
            }<commit_msg>Make sure we read properties with UTF8 encoding during live-reload<commit_after>package io.quarkus.undertow.websockets.deployment;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;

import org.jboss.logging.Logger;

import io.quarkus.deployment.devmode.HotReplacementContext;
import io.quarkus.deployment.devmode.HotReplacementSetup;
import io.quarkus.undertow.runtime.UndertowDeploymentRecorder;
import io.undertow.Handlers;
import io.undertow.predicate.Predicates;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ServletContainer;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;

public class WebsocketHotReloadSetup implements HotReplacementSetup {

    private static Logger logger = Logger.getLogger(WebsocketHotReloadSetup.class);

    static volatile String replacementPassword;

    @Override
    public void setupHotDeployment(HotReplacementContext hotReplacementContext) {
        // we can't use the typical ConfigProvider.getConfig() because the config infrastructure isn't setup at this point
        String password = System.getProperty(HotReplacementWebsocketEndpoint.QUARKUS_LIVE_RELOAD_PASSWORD);
        if (password == null || password.isEmpty()) {
            password = System.getenv(HotReplacementWebsocketEndpoint.QUARKUS_LIVE_RELOAD_PASSWORD_ENV);
        }

        if (password != null && !password.isEmpty()) {
            replacementPassword = password;
        } else {
            List<Path> resources = hotReplacementContext.getResourcesDir();
            if (!resources.isEmpty()) {
                //TODO: fix this
                File appConfig = resources.get(0).resolve("application.properties").toFile();
                if (appConfig.isFile()) {
                    try (InputStream is = new FileInputStream(appConfig)) {
                        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
                            try (BufferedReader br = new BufferedReader(isr)) {
                                Properties p = new Properties();
                                p.load(br);
                                replacementPassword = p
                                        .getProperty(HotReplacementWebsocketEndpoint.QUARKUS_LIVE_RELOAD_PASSWORD);
                            }
                        }
                    } catch (IOException e) {
                        logger.error("Failed to read application.properties", e);
                    }
                }
            }
{'fraction_non_alphanumeric': 0.08583131632843045, 'fraction_numerical': 0.0007447402718301992, 'mean_word_length': 2.8398856325947106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5112852', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1370, 'n_words': 277}