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

ar.gabrielsuarez.glib.core.XResource Maven / Gradle / Ivy

The newest version!
package ar.gabrielsuarez.glib.core;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import ar.gabrielsuarez.glib.G;

public abstract class XResource {

	/* ========== RESOURCE ========== */
	public static InputStream resourceInputStream(String path) {
		return Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
	}

	public static byte[] resourceBytes(String path) {
		return G.toBytes(resourceInputStream(path));
	}

	public static String resourceBase64(String path) {
		return G.base64(resourceBytes(path));
	}

	/* ========== PROPERTIES ========== */
	public static Properties properties(String path) {
		Properties properties = new Properties();
		try (InputStream is = resourceInputStream(path)) {
			properties.load(is);
		} catch (Exception e) {
			throw G.runtimeException(e);
		}
		return properties;
	}

	public static Map propertiesToMap(String path) {
		Map map = new HashMap<>();
		Properties properties = properties(path);
		for (Object key : properties.keySet()) {
			map.put(key.toString(), properties.getProperty(key.toString()).trim());
		}
		return map;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy