类 DescriptiveResource
- java.lang.Object
- org.springframework.core.io.AbstractResource
- org.springframework.core.io.DescriptiveResource
- 所有已实现的接口:
InputStreamSource,Resource
public class DescriptiveResource extends AbstractResource
SimpleResourceimplementation that holds a resource description but does not point to an actually readable resource.To be used as placeholder if a
Resourceargument is expected by an API but not necessarily used for actual reading.- 从以下版本开始:
- 1.2.6
- 作者:
- Juergen Hoeller
构造器概要
构造器 构造器 说明 DescriptiveResource(String description)Create a new DescriptiveResource.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 booleanequals(Object other)This implementation compares the underlying description String.booleanexists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.StringgetDescription()Return a description for this resource, to be used for error output when working with the resource.InputStreamgetInputStream()Return anInputStreamfor the content of an underlying resource.inthashCode()This implementation returns the hash code of the underlying description String.booleanisReadable()This implementation always returnstruefor a resource thatexists(revised as of 5.1).从类继承的方法 org.springframework.core.io.AbstractResource
contentLength, createRelative, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, isFile, isOpen, lastModified, readableChannel, toString
构造器详细资料
DescriptiveResource
public DescriptiveResource(@Nullable String description)
Create a new DescriptiveResource.- 参数:
description- the resource description
方法详细资料
exists
public boolean exists()
从类复制的说明:AbstractResourceThis 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.- 指定者:
exists在接口中Resource- 覆盖:
exists在类中AbstractResource
isReadable
public boolean isReadable()
从类复制的说明:AbstractResourceThis implementation always returnstruefor a resource thatexists(revised as of 5.1).- 指定者:
isReadable在接口中Resource- 覆盖:
isReadable在类中AbstractResource- 另请参阅:
InputStreamSource.getInputStream(),Resource.exists()
getInputStream
public InputStream getInputStream() throws IOException
从接口复制的说明:InputStreamSourceReturn anInputStreamfor the content of an underlying resource.It is expected that each call creates a fresh stream.
This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each
getInputStream()call returns a fresh stream.- 返回:
- the input stream for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource doesn't existIOException- if the content stream could not be opened
getDescription
public String getDescription()
从接口复制的说明: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.- 另请参阅:
Object.toString()
equals
public boolean equals(@Nullable Object other)
This implementation compares the underlying description String.- 覆盖:
equals在类中AbstractResource- 另请参阅:
Resource.getDescription()
hashCode
public int hashCode()
This implementation returns the hash code of the underlying description String.- 覆盖:
hashCode在类中AbstractResource- 另请参阅:
Resource.getDescription()