public class DescriptiveResource extends AbstractResource
Resource implementation that holds a resource description
but does not point to an actually readable resource.
To be used as placeholder if a Resource argument is
expected by an API but not necessarily used for actual reading.
| Constructor and Description |
|---|
DescriptiveResource(String description)
Create a new DescriptiveResource.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object other)
This implementation compares the underlying description String.
|
boolean |
exists()
This implementation checks whether a File can be opened,
falling back to whether an InputStream can be opened.
|
String |
getDescription()
Return a description for this resource,
to be used for error output when working with the resource.
|
InputStream |
getInputStream()
Return an
InputStream for the content of an underlying resource. |
int |
hashCode()
This implementation returns the hash code of the underlying description String.
|
boolean |
isReadable()
This implementation always returns
true for a resource
that exists (revised as of 5.1). |
contentLength, createRelative, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, isFile, isOpen, lastModified, readableChannel, toStringpublic boolean exists()
AbstractResourceThis will cover both directories and content resources.
exists in interface Resourceexists in class AbstractResourcepublic boolean isReadable()
AbstractResourcetrue for a resource
that exists (revised as of 5.1).isReadable in interface ResourceisReadable in class AbstractResourceInputStreamSource.getInputStream(),
Resource.exists()public InputStream getInputStream() throws IOException
InputStreamSourceInputStream for 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.
null)FileNotFoundException - if the underlying resource does not existIOException - if the content stream could not be openedResource.isReadable()public String getDescription()
ResourceImplementations are also encouraged to return this value
from their toString method.
Object.toString()public boolean equals(@Nullable Object other)
equals in class AbstractResourceResource.getDescription()public int hashCode()
hashCode in class AbstractResourceResource.getDescription()