1 29 30 package nextapp.echo2.app.util; 31 32 import java.io.IOException ; 33 import java.io.InputStream ; 34 import java.net.URL ; 35 import java.util.Enumeration ; 36 import java.util.HashMap ; 37 import java.util.Map ; 38 import java.util.Properties ; 39 40 44 public class PropertiesDiscovery { 45 46 55 public static Map loadProperties(String resourceName, ClassLoader classLoader) 56 throws IOException { 57 Map propertyMap = new HashMap (); 58 Enumeration resources = classLoader.getResources(resourceName); 59 while (resources.hasMoreElements()) { 60 URL resourceUrl = (URL ) resources.nextElement(); 61 Properties peerProperties = new Properties (); 62 InputStream in = resourceUrl.openStream(); 63 try { 64 peerProperties.load(in); 65 propertyMap.putAll(peerProperties); 66 } finally { 67 in.close(); 68 } 69 } 70 return propertyMap; 71 } 72 73 74 private PropertiesDiscovery() { } 75 } | Popular Tags |