public abstract class AbstractResource extends Object implements Resource
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.
| Constructor and Description |
|---|
AbstractResource() |
| Modifier and Type | Method and Description |
|---|---|
long |
contentLength()
This method reads the entire InputStream to determine 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 other)
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 returns
null,
assuming that this resource type does not have a filename. |
URI |
getURI()
This implementation builds a URI based on the URL returned
by
getURL(). |
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 |
isFile()
This implementation always returns
false. |
boolean |
isOpen()
This implementation always returns
false. |
boolean |
isReadable()
This implementation always returns
true for a resource
that exists (revised as of 5.1). |
long |
lastModified()
This implementation checks the timestamp of the underlying File,
if available.
|
ReadableByteChannel |
readableChannel()
This implementation returns
Channels.newChannel(InputStream)
with the result of InputStreamSource.getInputStream(). |
String |
toString()
This implementation returns the description of this resource.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitgetDescriptiongetInputStreampublic boolean exists()
public boolean isReadable()
true for a resource
that exists (revised as of 5.1).isReadable in interface ResourceInputStreamSource.getInputStream(),
Resource.exists()public boolean isOpen()
false.public boolean isFile()
false.isFile in interface ResourceResource.getFile()public URL getURL() throws IOException
getURL in interface ResourceIOException - if the resource cannot be resolved as URL,
i.e. if the resource is not available as descriptorpublic URI getURI() throws IOException
getURL().getURI in interface ResourceIOException - if the resource cannot be resolved as URI,
i.e. if the resource is not available as descriptorpublic File getFile() throws IOException
getFile in interface ResourceFileNotFoundException - 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 failuresInputStreamSource.getInputStream()public ReadableByteChannel readableChannel() throws IOException
Channels.newChannel(InputStream)
with the result of InputStreamSource.getInputStream().
This is the same as in Resource's corresponding default method
but mirrored here for efficient JVM-level dispatching in a class hierarchy.
readableChannel in interface Resourcenull)FileNotFoundException - if the underlying resource doesn't existIOException - if the content channel could not be openedInputStreamSource.getInputStream()public long contentLength()
throws IOException
For a custom sub-class 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 in interface ResourceIOException - if the resource cannot be resolved
(in the file system or as some other known physical resource type)InputStreamSource.getInputStream()public long lastModified()
throws IOException
lastModified in interface ResourceIOException - if the resource cannot be resolved
(in the file system or as some other known physical resource type)getFileForLastModifiedCheck()protected File getFileForLastModifiedCheck() throws IOException
The default implementation delegates to getFile().
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 failurespublic Resource createRelative(String relativePath) throws IOException
createRelative in interface ResourcerelativePath - the relative path (relative to this resource)IOException - if the relative resource cannot be determined@Nullable public String getFilename()
null,
assuming that this resource type does not have a filename.getFilename in interface Resourcepublic boolean equals(@Nullable Object other)
equals in class ObjectResource.getDescription()public int hashCode()
hashCode in class ObjectResource.getDescription()public String toString()
toString in class ObjectResource.getDescription()