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

net.morimekta.config.source.ResourceConfigSource Maven / Gradle / Ivy

There is a newer version: 2.7.1
Show newest version
package net.morimekta.config.source;

import net.morimekta.config.Config;
import net.morimekta.config.ConfigException;
import net.morimekta.config.format.ConfigFormat;

import java.io.IOException;
import java.io.InputStream;

/**
 * File source for config objects.
 */
public class ResourceConfigSource implements ConfigSource {
    private Config config;

    private final String       resource;
    private final ConfigFormat configFormat;

    public ResourceConfigSource(String resource, ConfigFormat format) {
        this.resource = resource;
        this.configFormat = format;
    }

    @Override
    public Config load() throws IOException, ConfigException {
        if (config == null) {
            loadInternal();
        }
        return config;
    }

    private void loadInternal() throws IOException, ConfigException {
        try (InputStream in = getClass().getResourceAsStream(resource)) {
            this.config = configFormat.parse(in);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy