All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.config.ConfigValuePropertiesConfigSource Maven / Gradle / Ivy

package io.smallrye.config;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import io.smallrye.config.common.utils.ConfigSourceUtil;

public class ConfigValuePropertiesConfigSource extends MapBackedConfigValueConfigSource {
    private static final long serialVersionUID = 9070158352250209380L;

    private static final String NAME_PREFIX = "ConfigValuePropertiesConfigSource[source=";

    public ConfigValuePropertiesConfigSource(URL url) throws IOException {
        this(url, DEFAULT_ORDINAL);
    }

    public ConfigValuePropertiesConfigSource(URL url, int defaultOrdinal) throws IOException {
        this(url, NAME_PREFIX + url.toString() + "]", defaultOrdinal);
    }

    private ConfigValuePropertiesConfigSource(URL url, String name, int defaultOrdinal) throws IOException {
        super(name, urlToConfigValueMap(url, name, defaultOrdinal));
    }

    public ConfigValuePropertiesConfigSource(Map properties, String name, int defaultOrdinal) {
        super(NAME_PREFIX + name + "]",
                new ConfigValueMapStringView(properties, name, ConfigSourceUtil.getOrdinalFromMap(properties, defaultOrdinal)),
                defaultOrdinal);
    }

    private static Map urlToConfigValueMap(URL locationOfProperties, String name, int ordinal)
            throws IOException {
        try (InputStreamReader reader = new InputStreamReader(locationOfProperties.openStream(), StandardCharsets.UTF_8)) {
            ConfigValueProperties p = new ConfigValueProperties(name, ordinal);
            p.load(reader);
            return p;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy