public abstract class

AbstractResource

extends Object
implements Resource
java.lang.Object
   ↳ org.springframework.core.io.AbstractResource
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Convenience base class for 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.

Summary

Public Constructors
AbstractResource()
Public Methods
long contentLength()
This implementation checks the timestamp of the underlying File, if available.
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.
String getFilename()
This implementation always throws IllegalStateException, assuming that the resource 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 isOpen()
This implementation always returns false.
boolean isReadable()
This implementation always returns true.
long lastModified()
This implementation checks the timestamp of the underlying File, if available.
String toString()
This implementation returns the description of this resource.
Protected Methods
File getFileForLastModifiedCheck()
Determine the File to use for timestamp checking.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.core.io.InputStreamSource
From interface org.springframework.core.io.Resource

Public Constructors

public AbstractResource ()

Also: SpringCore

Public Methods

public long contentLength ()

Also: SpringCore

This implementation checks the timestamp of the underlying File, if available.

Throws
IOException
See Also

public Resource createRelative (String relativePath)

Also: SpringCore

This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.

Parameters
relativePath the relative path (relative to this resource)
Returns
  • the resource handle for the relative resource
Throws
IOException

public boolean equals (Object obj)

This implementation compares description strings.

See Also

public boolean exists ()

Also: SpringCore

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.

public File getFile ()

Also: SpringCore

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.

Throws
IOException

public String getFilename ()

Also: SpringCore

This implementation always throws IllegalStateException, assuming that the resource does not have a filename.

public URI getURI ()

Also: SpringCore

This implementation builds a URI based on the URL returned by getURL().

Throws
IOException

public URL getURL ()

Also: SpringCore

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.

Throws
IOException

public int hashCode ()

This implementation returns the description's hash code.

See Also

public boolean isOpen ()

Also: SpringCore

This implementation always returns false.

public boolean isReadable ()

Also: SpringCore

This implementation always returns true.

public long lastModified ()

Also: SpringCore

This implementation checks the timestamp of the underlying File, if available.

Throws
IOException

public String toString ()

This implementation returns the description of this resource.

See Also

Protected Methods

protected File getFileForLastModifiedCheck ()

Also: SpringCore

Determine the File to use for timestamp checking.

The default implementation delegates to getFile().

Returns
  • the File to use for timestamp checking (never null)
Throws
IOException if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system