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

com.github.httpmock.exec.PropertiesReader Maven / Gradle / Ivy

The newest version!
package com.github.httpmock.exec;

import com.github.httpmock.ServerException;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertiesReader {
	private ClassLoader classLoader;

	public PropertiesReader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}

	private static final String UTF_8 = "UTF-8";

	public Properties read(String resourceName) {
		InputStream is = classLoader.getResourceAsStream(resourceName);
		if (is == null)
			throw new ServerException("resource not found: " + resourceName);
		try {
			return loadProperties(is);
		} catch (IOException e) {
			throw new ServerException(e);
		}
	}

	private Properties loadProperties(InputStream is) throws IOException {
		Properties config = new Properties();
		config.load(new InputStreamReader(is, UTF_8));
		is.close();
		return config;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy