Search in sources :

Example 1 with OrderedProperties

use of org.mule.runtime.core.internal.util.OrderedProperties in project mule by mulesoft.

the class PropertiesUtils method discoverProperties.

/**
 * Discovers properties files available on the given classloader.
 *
 * @param classLoader classloader used to find properties resources. Not null.
 * @param resource resource to find. Not empty
 * @return a non null list of Properties
 * @throws IOException when a property file cannot be processed
 */
public static List<Properties> discoverProperties(ClassLoader classLoader, String resource) throws IOException {
    checkArgument(!isEmpty(resource), "Resource cannot be empty");
    checkArgument(classLoader != null, "ClassLoader cannot be null");
    List<Properties> result = new LinkedList<>();
    Enumeration<URL> allPropertiesResources = classLoader.getResources(resource);
    while (allPropertiesResources.hasMoreElements()) {
        URL propertiesResource = allPropertiesResources.nextElement();
        if (logger.isDebugEnabled()) {
            logger.debug("Reading properties from: " + propertiesResource.toString());
        }
        Properties properties = new OrderedProperties();
        try (InputStream resourceStream = propertiesResource.openStream()) {
            properties.load(resourceStream);
        }
        result.add(properties);
    }
    return result;
}
Also used : InputStream(java.io.InputStream) OrderedProperties(org.mule.runtime.core.internal.util.OrderedProperties) Properties(java.util.Properties) OrderedProperties(org.mule.runtime.core.internal.util.OrderedProperties) LinkedList(java.util.LinkedList) URL(java.net.URL)

Aggregations

InputStream (java.io.InputStream)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 OrderedProperties (org.mule.runtime.core.internal.util.OrderedProperties)1