/** * This is a convenience method to load a resource as a stream. * <p/> * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return (url != null) ? url.openStream() : null; } catch(IOException e) { return null; } }
return getResource('/' + resourceName, callingClass);
private void tryClasspath(String uriStr) throws IOException { if (uriStr.startsWith("classpath:")) { uriStr = uriStr.substring(10); } URL url = ClassLoaderUtils.getResource(uriStr, getClass()); if (url == null) { tryRemote(uriStr); } else { try { String decodedURL = url.toString(); uri = new URI(URLEncoder.encode(decodedURL, "UTF-8")); } catch (URISyntaxException e) { // this occurs when you have spaces instead of '%20'... } is = url.openStream(); this.url = url; } }
mapping.loadMapping(ClassLoaderUtils.getResource(mappingFile, CastorTypeCreator.class));