类 ClassPathResource
java.lang.Object
com.alibaba.nacos.common.packagescan.resource.AbstractResource
com.alibaba.nacos.common.packagescan.resource.AbstractFileResolvingResource
com.alibaba.nacos.common.packagescan.resource.ClassPathResource
- 所有已实现的接口:
InputStreamSource,Resource
Copy from https://github.com/spring-projects/spring-framework.git, with less modifications
Resource implementation for class path resources. Uses either a
given ClassLoader or a given Class for loading resources.
Supports resolution as java.io.File if the class path
resource resides in the file system, but not for resources in a JAR.
Always supports resolution as URL.
- 从以下版本开始:
- 28.12.2003
- 作者:
- Juergen Hoeller, Sam Brannen
- 另请参阅:
-
构造器概要
构造器限定符构造器说明ClassPathResource(String path) Create a newClassPathResourceforClassLoaderusage.ClassPathResource(String path, Class<?> clazz) Create a newClassPathResourceforClassusage.ClassPathResource(String path, ClassLoader classLoader) Create a newClassPathResourceforClassLoaderusage.protectedClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) 已过时。 -
方法概要
修饰符和类型方法说明createRelative(String relativePath) This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.booleanThis implementation compares the underlying class path locations.booleanexists()This implementation checks for the resolution of a resource URL.final ClassLoaderReturn the ClassLoader that this resource will be obtained from.This implementation returns a description that includes the class path location.This implementation returns the name of the file that this class path resource refers to.This implementation opens an InputStream for the given class path resource.final StringgetPath()Return the path for this resource (as resource path within the class path).getUrl()This implementation returns a URL for the underlying class path resource, if available.inthashCode()This implementation returns the hash code of the underlying class path location.booleanThis implementation checks for the resolution of a resource URL upfront, then proceeding withAbstractFileResolvingResource's length check.protected URLResolves a URL for the underlying class path resource.从类继承的方法 com.alibaba.nacos.common.packagescan.resource.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, getFile, getFile, getFileForLastModifiedCheck, isFile, isFile, lastModified, readableChannel从类继承的方法 com.alibaba.nacos.common.packagescan.resource.AbstractResource
getUri, isOpen, toString
-
构造器详细资料
-
ClassPathResource
Create a newClassPathResourceforClassLoaderusage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.The thread context class loader will be used for loading the resource.
- 参数:
path- the absolute path within the class path- 另请参阅:
-
ClassPathResource
Create a newClassPathResourceforClassLoaderusage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.- 参数:
path- the absolute path within the classpathclassLoader- the class loader to load the resource with, ornullfor the thread context class loader- 另请参阅:
-
ClassPathResource
Create a newClassPathResourceforClassusage. The path can be relative to the given class, or absolute within the classpath via a leading slash.- 参数:
path- relative or absolute path within the class pathclazz- the class to load resources with- 另请参阅:
-
ClassPathResource
已过时。as of 4.3.13, in favor of selective use ofClassPathResource(String, ClassLoader)vsClassPathResource(String, Class)Create a newClassPathResourcewith optionalClassLoaderandClass. Only for internal usage.- 参数:
path- relative or absolute path within the classpathclassLoader- the class loader to load the resource with, if anyclazz- the class to load resources with, if any
-
-
方法详细资料
-
getPath
Return the path for this resource (as resource path within the class path). -
getClassLoader
Return the ClassLoader that this resource will be obtained from. -
exists
public boolean exists()This implementation checks for the resolution of a resource URL.- 指定者:
exists在接口中Resource- 覆盖:
exists在类中AbstractFileResolvingResource- 另请参阅:
-
isReadable
public boolean isReadable()This implementation checks for the resolution of a resource URL upfront, then proceeding withAbstractFileResolvingResource's length check.- 指定者:
isReadable在接口中Resource- 覆盖:
isReadable在类中AbstractFileResolvingResource- 另请参阅:
-
resolveUrl
Resolves a URL for the underlying class path resource.- 返回:
- the resolved URL, or
nullif not resolvable
-
getInputStream
This implementation opens an InputStream for the given class path resource.- 返回:
- the input stream for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource does not existIOException- if the content stream could not be opened- 另请参阅:
-
getUrl
This implementation returns a URL for the underlying class path resource, if available.- 指定者:
getUrl在接口中Resource- 覆盖:
getUrl在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor- 另请参阅:
-
createRelative
This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.- 指定者:
createRelative在接口中Resource- 覆盖:
createRelative在类中AbstractResource- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 另请参阅:
-
getFilename
This implementation returns the name of the file that this class path resource refers to.- 指定者:
getFilename在接口中Resource- 覆盖:
getFilename在类中AbstractResource- 另请参阅:
-
getDescription
This implementation returns a description that includes the class path location.- 另请参阅:
-
equals
This implementation compares the underlying class path locations.- 覆盖:
equals在类中AbstractResource- 另请参阅:
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying class path location.- 覆盖:
hashCode在类中AbstractResource- 另请参阅:
-
ClassPathResource(String, ClassLoader)vsClassPathResource(String, Class)