类 AbstractResource
- java.lang.Object
- org.springframework.core.io.AbstractResource
- 所有已实现的接口:
InputStreamSource
,Resource
- 直接已知子类:
AbstractFileResolvingResource
,ByteArrayResource
,DescriptiveResource
,FileSystemResource
,InputStreamResource
,PathResource
,VfsResource
public abstract class AbstractResource extends Object implements Resource
Convenience base class forResource
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.
- 从以下版本开始:
- 28.12.2003
- 作者:
- Juergen Hoeller
构造器概要
构造器 构造器 说明 AbstractResource()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 long
contentLength()
This implementation reads the entire InputStream to calculate the content length.Resource
createRelative(String relativePath)
This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.boolean
equals(Object obj)
This implementation compares description strings.boolean
exists()
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.File
getFile()
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.protected File
getFileForLastModifiedCheck()
Determine the File to use for timestamp checking.String
getFilename()
This implementation always returnsnull
, assuming that this resource type does not have a filename.URI
getURI()
This implementation builds a URI based on the URL returned bygetURL()
.URL
getURL()
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.int
hashCode()
This implementation returns the description's hash code.boolean
isOpen()
This implementation always returnsfalse
.boolean
isReadable()
This implementation always returnstrue
.long
lastModified()
This implementation checks the timestamp of the underlying File, if available.String
toString()
This implementation returns the description of this resource.从接口继承的方法 org.springframework.core.io.InputStreamSource
getInputStream
从接口继承的方法 org.springframework.core.io.Resource
getDescription
构造器详细资料
AbstractResource
public AbstractResource()
方法详细资料
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 returnstrue
.- 指定者:
isReadable
在接口中Resource
- 另请参阅:
InputStreamSource.getInputStream()
getURL
public URL getURL() throws IOException
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.- 指定者:
getURL
在接口中Resource
- 抛出:
IOException
- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
getURI
public URI getURI() throws IOException
This implementation builds a URI based on the URL returned bygetURL()
.- 指定者:
getURI
在接口中Resource
- 抛出:
IOException
- if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
getFile
public File getFile() throws IOException
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.- 指定者:
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- 另请参阅:
InputStreamSource.getInputStream()
contentLength
public long contentLength() throws IOException
This implementation reads the entire InputStream to calculate the content length. Subclasses will almost always be able to provide a more optimal version of this, e.g. checking a File length.- 指定者:
contentLength
在接口中Resource
- 抛出:
IOException
- if the resource cannot be resolved (in the file system or as some other known physical resource type)- 另请参阅:
InputStreamSource.getInputStream()
lastModified
public long lastModified() throws IOException
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()
getFileForLastModifiedCheck
protected File getFileForLastModifiedCheck() throws IOException
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
public Resource createRelative(String relativePath) throws IOException
This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for 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
getFilename
public String getFilename()
This implementation always returnsnull
, assuming that this resource type does not have a filename.- 指定者:
getFilename
在接口中Resource
toString
public String toString()
This implementation returns the description of this resource.- 覆盖:
toString
在类中Object
- 另请参阅:
Resource.getDescription()
equals
public boolean equals(Object obj)
This implementation compares description strings.- 覆盖:
equals
在类中Object
- 另请参阅:
Resource.getDescription()
hashCode
public int hashCode()
This implementation returns the description's hash code.- 覆盖:
hashCode
在类中Object
- 另请参阅:
Resource.getDescription()