类 AbstractResource
- 所有已实现的接口:
InputStreamSource,Resource
- 直接已知子类:
AbstractFileResolvingResource,ByteArrayResource,DescriptiveResource,FileSystemResource,InputStreamResource,ModuleResource,PathResource
Resource implementations,
pre-implementing typical behavior.
The "exists" method will check whether a File or InputStream can be opened; "isOpen" will always return false; "getURL" and "getFile" throw an exception; and "toString" will return the description.
- 从以下版本开始:
- 2.1.6 2019-05-14
- 作者:
- Juergen Hoeller, Sam Brannen, Harry Yang
-
字段概要
从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明longThis method reads the entire InputStream to determine the content length.createRelative(String relativePath) Create a resource relative to this resource.protected voidCustomize the givenHttpURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.protected voidCustomize the givenURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.booleanbooleanexists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.getFile()Return a File handle for this resource.protected FileDetermine the File to use for timestamp checking.private LoggergetName()Determine the filename for this resource — 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.inthashCode()booleanTests whether the resource denoted by this abstract pathname is a directory.booleanisFile()This implementation always returnsfalse.booleanisOpen()This implementation always returnsfalse.booleanThis implementation always returnstruefor a resource thatexists(revised as of 5.1).longThis implementation checks the timestamp of the underlying File, if available.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从接口继承的方法 cn.taketoday.core.io.Resource
getContentAsByteArray, getContentAsString
-
构造器详细资料
-
AbstractResource
public AbstractResource()
-
-
方法详细资料
-
getName
Determine 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.
-
exists
public boolean exists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.This will cover both directories and content resources.
-
isReadable
public boolean isReadable()This implementation always returnstruefor a resource thatexists(revised as of 5.1).- 指定者:
isReadable在接口中Resource- 另请参阅:
-
customizeConnection
Customize the givenURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.Calls
ResourceUtils.useCachesIfNecessary(URLConnection)and delegates tocustomizeConnection(HttpURLConnection)if possible. Can be overridden in subclasses.- 参数:
con- the URLConnection to customize- 抛出:
IOException- if thrown from URLConnection methods
-
customizeConnection
Customize the givenHttpURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.Sets request method "HEAD" by default. Can be overridden in subclasses.
- 参数:
con- the HttpURLConnection to customize- 抛出:
IOException- if thrown from HttpURLConnection methods
-
isOpen
public boolean isOpen()This implementation always returnsfalse. -
isFile
public boolean isFile()This implementation always returnsfalse. -
getURL
从接口复制的说明:ResourceReturn a URL handle for this resource.- 指定者:
getURL在接口中Resource- 抛出:
IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
-
getURI
从接口复制的说明:ResourceReturn a URI handle for this resource.- 指定者:
getURI在接口中Resource- 抛出:
IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
-
getFile
从接口复制的说明:ResourceReturn a File handle for this resource.- 指定者:
getFile在接口中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- 另请参阅:
-
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- 返回:
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- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
list
从接口复制的说明:ResourcelistResourceunder the directory- 指定者:
list在接口中Resource- 参数:
filter- filterResource- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
contentLength
This method reads the entire InputStream to determine the content length.For a custom subclass of
InputStreamResource, we strongly recommend overriding this method with a more optimal implementation, e.g. checking File length, or possibly simply returning -1 if the stream can only be read once.- 指定者:
contentLength在接口中Resource- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- 另请参阅:
-
lastModified
This implementation checks the timestamp of the underlying File, if available.- 指定者:
lastModified在接口中Resource- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- 另请参阅:
-
getFileForLastModifiedCheck
Determine the File to use for timestamp checking.The default implementation delegates to
getFile().- 返回:
- the File to use for timestamp checking (never
null) - 抛出:
FileNotFoundException- if the resource cannot be resolved as an absolute file path, i.e. is not available in a file systemIOException- in case of general resolution/reading failures
-
createRelative
从接口复制的说明:ResourceCreate a resource relative to this resource.- 指定者:
createRelative在接口中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
从接口复制的说明:ResourceReturn 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. -
hashCode
public int hashCode() -
equals
-
getLogger
-