/** * Return a path suitable for use with {@code ClassLoader.getResource} * (also suitable for use with {@code Class.getResource} by prepending a * slash ('/') to the return value). Built by taking the package of the specified * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash * if necessary, and concatenating the specified resource name to this. * <br> As such, this function may be used to build a path suitable for * loading a resource file that is in the same package as a class file, * although ClassPathResource is usually * even more convenient. * * @param clazz the Class whose package will be used as the base * @param resourceName the resource name to append. A leading slash is optional. * @return the built-up resource path * @see ClassLoader#getResource * @see Class#getResource */ public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) { Assert.notNull(resourceName, "Resource name must not be null"); if (!resourceName.startsWith("/")) { return classPackageAsResourcePath(clazz) + "/" + resourceName; } return classPackageAsResourcePath(clazz) + resourceName; }
/** * Return a path suitable for use with {@code ClassLoader.getResource} * (also suitable for use with {@code Class.getResource} by prepending a * slash ('/') to the return value). Built by taking the package of the specified * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash * if necessary, and concatenating the specified resource name to this. * <br> As such, this function may be used to build a path suitable for * loading a resource file that is in the same package as a class file, * although ClassPathResource is usually * even more convenient. * * @param clazz the Class whose package will be used as the base * @param resourceName the resource name to append. A leading slash is optional. * @return the built-up resource path * @see ClassLoader#getResource * @see Class#getResource */ public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) { Assert.notNull(resourceName, "Resource name must not be null"); if (!resourceName.startsWith("/")) { return classPackageAsResourcePath(clazz) + "/" + resourceName; } return classPackageAsResourcePath(clazz) + resourceName; }
/** * Return a path suitable for use with {@code ClassLoader.getResource} * (also suitable for use with {@code Class.getResource} by prepending a * slash ('/') to the return value). Built by taking the package of the specified * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash * if necessary, and concatenating the specified resource name to this. * <br> As such, this function may be used to build a path suitable for * loading a resource file that is in the same package as a class file, * although ClassPathResource is usually * even more convenient. * @param clazz the Class whose package will be used as the base * @param resourceName the resource name to append. A leading slash is optional. * @return the built-up resource path * @see ClassLoader#getResource * @see Class#getResource */ public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) { Assert.notNull(resourceName, "Resource name must not be null"); if (!resourceName.startsWith("/")) { return classPackageAsResourcePath(clazz) + "/" + resourceName; } return classPackageAsResourcePath(clazz) + resourceName; }
/** * This implementation returns a description that includes the class path location. */ @Override public String getDescription() { StringBuilder builder = new StringBuilder("class path resource ["); String pathToUse = path; if (this.clazz != null && !pathToUse.startsWith("/")) { builder.append(ClassUtils.classPackageAsResourcePath(this.clazz)); builder.append('/'); } if (pathToUse.startsWith("/")) { pathToUse = pathToUse.substring(1); } builder.append(pathToUse); builder.append(']'); return builder.toString(); }
/** * This implementation returns a description that includes the class path location. */ @Override public String getDescription() { StringBuilder builder = new StringBuilder("class path resource ["); String pathToUse = path; if (this.clazz != null && !pathToUse.startsWith("/")) { builder.append(ClassUtils.classPackageAsResourcePath(this.clazz)); builder.append('/'); } if (pathToUse.startsWith("/")) { pathToUse = pathToUse.substring(1); } builder.append(pathToUse); builder.append(']'); return builder.toString(); }
/** * This implementation returns a description that includes the class path location. */ @Override public String getDescription() { StringBuilder builder = new StringBuilder("class path resource ["); String pathToUse = path; if (this.clazz != null && !pathToUse.startsWith("/")) { builder.append(ClassUtils.classPackageAsResourcePath(this.clazz)); builder.append('/'); } if (pathToUse.startsWith("/")) { pathToUse = pathToUse.substring(1); } builder.append(pathToUse); builder.append(']'); return builder.toString(); }