接口 Resource
- 所有超级接口:
InputStreamSource
- 所有已知子接口:
ContextResource,WritableResource
- 所有已知实现类:
AbstractFileResolvingResource,AbstractResource,ByteArrayResource,ClassPathResource,ClassRelativeResourceLoader.ClassRelativeContextResource,DefaultResourceLoader.ClassPathContextResource,DescriptiveResource,FileSystemResource,FileSystemResourceLoader.FileSystemContextResource,FileUrlResource,InputStreamResource,ModuleResource,PathResource,ResourceDecorator,UrlResource,WritableResourceDecorator
An InputStream can be opened for every resource if it exists in physical form, but a URL or File handle can just be returned for certain resources. The actual behavior is implementation-specific.
- 从以下版本开始:
- 2.1.6 2019-05-14 19:55
- 作者:
- Juergen Hoeller, Arjen Poutsma, Harry Yang
- 另请参阅:
-
字段概要
字段 -
方法概要
修饰符和类型方法说明longDetermine the content length for this resource.createRelative(String relativePath) Create a resource relative to this resource.booleanexists()Determine whether this resource actually exists in physical form.default byte[]Return the contents of this resource as a byte array.default StringgetContentAsString(Charset charset) Returns the contents of this resource as a string, using the specified charset.getFile()Return a File handle for this resource.getName()Determine a name for this resource, i.e. typically the last part of the path: for example, "myfile.txt".getURI()Return a URI handle for this resource.getURL()Return a URL handle for this resource.booleanTests whether the resource denoted by this abstract pathname is a directory.default booleanisFile()Determine whether this resource represents a file in a file system.default booleanisOpen()Indicate whether this resource represents a handle with an open stream.default booleanIndicate whether non-empty contents of this resource can be read viaInputStreamSource.getInputStream().longDetermine the last-modified timestamp for this resource.String[]list()listResourceunder the directoryResource[]list(ResourceFilter filter) listResourceunder the directorytoString()Return a description for this resource, to be used for error output when working with the resource.从接口继承的方法 cn.taketoday.core.io.InputStreamSource
getInputStream, getReader, getReader, readableChannel
-
字段详细资料
-
EMPTY_ARRAY
-
-
方法详细资料
-
getName
Determine a name for this resource, i.e. typically the last part of the path: for example, "myfile.txt".Returns
nullif this type of resource does not have a filename. -
contentLength
Determine the content length for this resource.- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
-
lastModified
Determine the last-modified timestamp for this resource.- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
-
getURL
Return a URL handle for this resource.- 抛出:
IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
-
getURI
Return a URI handle for this resource.- 抛出:
IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor- 从以下版本开始:
- 2.1.7
-
getFile
Return a File handle for this resource.- 抛出:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures- 另请参阅:
-
getContentAsByteArray
Return the contents of this resource as a byte array.- 返回:
- the contents of this resource as byte array
- 抛出:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures- 从以下版本开始:
- 4.0
-
getContentAsString
Returns the contents of this resource as a string, using the specified charset.- 参数:
charset- the charset to use for decoding- 返回:
- the contents of this resource as a
String - 抛出:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures- 从以下版本开始:
- 4.0
-
exists
boolean exists()Determine whether this resource actually exists in physical form.This method performs a definitive existence check, whereas the existence of a
Resourcehandle only guarantees a valid descriptor handle. -
isReadable
default boolean isReadable()Indicate whether non-empty contents of this resource can be read viaInputStreamSource.getInputStream().Will be
truefor typical resource descriptors that exist since it strictly impliesexists()semantics. Note that actual content reading may still fail when attempted. However, a value offalseis a definitive indication that the resource content cannot be read. -
isOpen
default boolean isOpen()Indicate whether this resource represents a handle with an open stream. Iftrue, the InputStream cannot be read multiple times, and must be read and closed to avoid resource leaks.Will be
falsefor typical resource descriptors. -
isFile
default boolean isFile()Determine whether this resource represents a file in a file system.A value of
truestrongly suggests (but does not guarantee) that agetFile()call will succeed.This is conservatively
falseby default.- 从以下版本开始:
- 4.0
- 另请参阅:
-
isDirectory
Tests 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.- 返回:
trueif and only if the file denoted by this abstract pathname exists and is a directory;falseotherwise- 抛出:
IOException- cannot determine resource
-
list
listResourceunder the directory- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
list
listResourceunder the directory- 参数:
filter- filterResource- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
createRelative
Create a resource relative to this resource.- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 抛出:
IOException- if the relative resource cannot be determined
-
toString
String toString()Return a description for this resource, to be used for error output when working with the resource.Implementations are also encouraged to return this value from their
toStringmethod.
-