Package org.cyclopsgroup.jmxterm.utils

Source Code of org.cyclopsgroup.jmxterm.utils.ExtendedPropertiesUtils

package org.cyclopsgroup.jmxterm.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;

import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.lang.Validate;

/**
* Utilities for loading overlapping properties files from classpath
*
* @author <a href="mailto:jiaqi.guo@gmail.com">Jiaqi Guo</a>
*/
public class ExtendedPropertiesUtils
{
    /**
     * @param resourcePath Path of overlapping properties files
     * @param classLoader Class loader where the resources are loaded
     * @return ExtendedProperties result
     * @throws IOException
     */
    public static ExtendedProperties loadFromOverlappingResources( String resourcePath, ClassLoader classLoader )
        throws IOException
    {
        Validate.notNull( resourcePath, "Resource path can't be NULL" );
        Validate.notNull( classLoader, "ClassLoader can't be NULL" );
        ExtendedProperties props = new ExtendedProperties();
        Enumeration<URL> resources = classLoader.getResources( resourcePath );
        while ( resources.hasMoreElements() )
        {
            InputStream resource = resources.nextElement().openStream();
            try
            {
                props.load( resource );
            }
            finally
            {
                resource.close();
            }
        }
        return props;
    }

    private ExtendedPropertiesUtils()
    {
    }
}
TOP

Related Classes of org.cyclopsgroup.jmxterm.utils.ExtendedPropertiesUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.