类 ClassPathResource
- 所有已实现的接口:
InputStreamSource,Resource,ThrowingConsumer<OutputStream>,Consumer<OutputStream>
- 直接已知子类:
ClassRelativeResourceLoader.ClassRelativeContextResource,DefaultResourceLoader.ClassPathContextResource
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.
- 从以下版本开始:
- 2019-05-14 21:47
- 作者:
- TODAY, Juergen Hoeller, Sam Brannen
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private final Stringprivate ClassLoaderprotected Resourceprivate final StringInternal representation of the original path supplied by the user, used for creating relative paths and resolving URLs and InputStreams.private Class<?>从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器构造器说明ClassPathResource(String path) Create a newClassPathResourceforClassLoaderusage.ClassPathResource(String path, Class<?> clazz) Create a newClassPathResourceforClassusage.ClassPathResource(String path, ClassLoader classLoader) Create a newClassPathResourceforClassLoaderusage. -
方法概要
修饰符和类型方法说明createRelative(String relativePath) Create a resource relative to this resource.booleanThis implementation compares the underlying class path locations and associated class loaders.booleanexists()This implementation checks for the resolution of a resource URL.final ClassLoaderReturn theClassLoaderthat this resource will be obtained from.final ResourceThis implementation opens anInputStreamfor the underlying class path resource, if available.getName()Determine the filename for this resource — typically the last part of the path — for example,"myfile.txt".final ResourceGet OriginalResourcefinal StringgetPath()Return the absolute path for this resource, as a cleaned 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.booleanTests whether the resource denoted by this abstract pathname is a directory.booleanThis implementation checks for the resolution of a resource URL upfront, then proceeding withAbstractFileResolvingResource's length check.String[]list()listResourceunder the directoryResource[]list(ResourceFilter filter) listResourceunder the directoryprotected URLResolves aURLfor the underlying class path resource.toString()This implementation returns a description that includes the absolute class path location.从类继承的方法 cn.taketoday.core.io.AbstractFileResolvingResource
checkReadable, contentLength, customizeConnection, customizeConnection, getFile, getFile, getFileForLastModifiedCheck, isFile, isFile, lastModified, readableChannel从类继承的方法 cn.taketoday.core.io.AbstractResource
getURI, isOpen从接口继承的方法 cn.taketoday.core.io.InputStreamSource
acceptWithException, getReader, getReader, transferTo从接口继承的方法 cn.taketoday.core.io.Resource
getContentAsByteArray, getContentAsString从接口继承的方法 cn.taketoday.util.function.ThrowingConsumer
accept, accept, throwing
-
字段详细资料
-
path
Internal representation of the original path supplied by the user, used for creating relative paths and resolving URLs and InputStreams. -
absolutePath
-
resourceClass
-
classLoader
-
delegate
-
-
构造器详细资料
-
ClassPathResource
Create a newClassPathResourceforClassLoaderusage.A leading slash will be removed, as the
ClassLoaderresource access methods will not accept it.The default 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
ClassLoaderresource access methods will not accept it.If the supplied
ClassLoaderisnull, the default class loader will be used for loading the resource.- 参数:
path- the absolute path within the class pathclassLoader- the class loader to load the resource with- 另请参阅:
-
ClassPathResource
Create a newClassPathResourceforClassusage.The path can be relative to the given class, or absolute within the class path via a leading slash.
If the supplied
Classisnull, the default class loader will be used for loading the resource.This is also useful for resource access within the module system, loading a resource from the containing module of a given
Class. SeeModuleResourceand its javadoc.- 参数:
path- relative or absolute path within the class pathclazz- the class to load resources with- 另请参阅:
-
-
方法详细资料
-
getDelegate
-
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 a descriptor- 另请参阅:
-
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- 另请参阅:
-
getInputStream
This implementation opens anInputStreamfor the underlying class path resource, if available.- 返回:
- 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- 另请参阅:
-
resolveURL
Resolves aURLfor the underlying class path resource.- 返回:
- the resolved URL, or
nullif not resolvable
-
isDirectory
从接口复制的说明:ResourceTests whether the resource denoted by this abstract pathname is a directory.Where it is required to distinguish an I/O exception from the case that the file is not a directory, or where several attributes of the same file are required at the same time, then the
Files.readAttributesmethod may be used.- 指定者:
isDirectory在接口中Resource- 覆盖:
isDirectory在类中AbstractResource- 返回:
trueif and only if the file denoted by this abstract pathname exists and is a directory;falseotherwise- 抛出:
IOException- cannot determine resource
-
list
从接口复制的说明:ResourcelistResourceunder the directory- 指定者:
list在接口中Resource- 覆盖:
list在类中AbstractResource- 参数:
filter- filterResource- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
list
从接口复制的说明:ResourcelistResourceunder the directory- 指定者:
list在接口中Resource- 覆盖:
list在类中AbstractResource- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
getName
从类复制的说明:AbstractResourceDetermine the filename for this resource — typically the last part of the path — for example,"myfile.txt".Returns
nullif this type of resource does not have a filename.Implementations are encouraged to return the filename unencoded.
- 指定者:
getName在接口中Resource- 覆盖:
getName在类中AbstractResource
-
createRelative
从接口复制的说明:ResourceCreate a resource relative to this resource.- 指定者:
createRelative在接口中Resource- 覆盖:
createRelative在类中AbstractResource- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
-
equals
This implementation compares the underlying class path locations and associated class loaders.- 覆盖:
equals在类中AbstractResource- 另请参阅:
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying class path location.- 覆盖:
hashCode在类中AbstractResource- 另请参阅:
-
getOriginalResource
Get OriginalResource- 返回:
- Original
Resource
-
getClassLoader
Return theClassLoaderthat this resource will be obtained from.- 从以下版本开始:
- 4.0
-
getPath
Return the absolute path for this resource, as a cleaned resource path within the class path.The path returned by this method does not have a leading slash and is suitable for use with
ClassLoader.getResource(String).- 从以下版本开始:
- 4.0
-
toString
This implementation returns a description that includes the absolute class path location.- 指定者:
toString在接口中Resource- 覆盖:
toString在类中AbstractResource- 另请参阅:
-