/** * Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the * ClassLoader resource access methods will not accept it. * * @param path the absolute path within the classpath * @param classLoader the class loader to load the resource with, or <code>null</code> for the * thread context class loader * @see java.lang.ClassLoader#getResourceAsStream(String) */ public ClassPathResource(String path, ClassLoader classLoader) { Assert.notNull(path, "Path must not be null"); String pathToUse = StringUtils.cleanPath(path); if (pathToUse.startsWith("/")) { pathToUse = pathToUse.substring(1); } this.path = pathToUse; this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); }
/** * Create a new ClassPathResource for Class usage. The path can be relative to the given class, or * absolute within the classpath via a leading slash. * * @param path relative or absolute path within the class path * @param clazz the class to load resources with * @see java.lang.Class#getResourceAsStream */ public ClassPathResource(String path, Class<?> clazz) { Assert.notNull(path, "Path must not be null"); this.path = StringUtils.cleanPath(path); this.clazz = clazz; }
/** * This implementation creates a ClassPathResource, applying the given path relative to the path * of the underlying resource of this descriptor. * * @see com.yh.android.framework.util.StringUtils#applyRelativePath(String, String) */ @Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new ClassPathResource(pathToUse, this.classLoader, this.clazz); }
/** * This implementation returns the name of the file that this class path resource refers to. * * @see com.yh.android.framework.util.StringUtils#getFilename(String) */ @Override public String getFilename() { return StringUtils.getFilename(this.path); }
/** * Create a new ClassPathResource with optional ClassLoader and Class. Only for internal usage. * * @param path relative or absolute path within the classpath * @param classLoader the class loader to load the resource with, if any * @param clazz the class to load resources with, if any */ protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) { this.path = StringUtils.cleanPath(path); this.classLoader = classLoader; this.clazz = clazz; }