1 16 package org.apache.log4j.lf5.util; 17 18 import java.io.InputStream ; 19 import java.net.URL ; 20 21 30 31 33 public class ResourceUtils { 34 38 42 46 50 54 71 public static InputStream getResourceAsStream(Object object, Resource resource) { 72 ClassLoader loader = object.getClass().getClassLoader(); 73 74 InputStream in = null; 75 76 if (loader != null) { 77 in = loader.getResourceAsStream(resource.getName()); 78 } else { 79 in = ClassLoader.getSystemResourceAsStream(resource.getName()); 80 } 81 82 return in; 83 } 84 85 100 public static URL getResourceAsURL(Object object, Resource resource) { 101 ClassLoader loader = object.getClass().getClassLoader(); 102 103 URL url = null; 104 105 if (loader != null) { 106 url = loader.getResource(resource.getName()); 107 } else { 108 url = ClassLoader.getSystemResource(resource.getName()); 109 } 110 111 return (url); 112 } 113 114 118 122 126 } 127 128 129 130 131 132 133 | Popular Tags |