List of usage examples for org.apache.commons.discovery Resource getResourceAsStream
public InputStream getResourceAsStream()
From source file:mitm.common.util.ResourceLocator.java
/** * tries to load the resource by name. Returns null if the resource cannot be found. *//*from ww w .j av a 2 s. c o m*/ @SuppressWarnings("resource") public InputStream getResourceAsStream(String resourceName) throws FileNotFoundException { InputStream input = null; File file = null; if (systemProperty != null) { String base = System.getProperty(systemProperty); if (base != null) { file = new File(base, resourceName); } } if (file == null || !file.exists()) { file = new File(baseDir, resourceName); } if (file.exists()) { logger.debug("Resource found at: " + file); input = new FileInputStream(file); } else { ClassLoaders classLoaders = ClassLoaders.getAppLoaders(null, null, true); Resource resource = ResourceUtils.getResource(null, resourceName, classLoaders); if (resource != null) { logger.debug("Resource found at: " + resource.getResource()); input = resource.getResourceAsStream(); } } return input; }
From source file:org.mule.config.dsl.util.ClasspathBuilder.java
/** * Getter of the input stream.// www. j av a2 s . c o m * * @return the input stream ready to use * @throws org.mule.config.dsl.IOException if resource not found * @see java.io.InputStream */ public InputStream get() throws IOException { if (content == null) { final Resource res = ResourceUtils.getResource(this.getClass(), path, null); if (res == null) { throw new IOException("Resource not found."); } this.content = res.getResourceAsStream(); } return content; }