org.springframework.core.io
Class AbstractResource

java.lang.Object
  extended byorg.springframework.core.io.AbstractResource
All Implemented Interfaces:
InputStreamSource, Resource
Direct Known Subclasses:
ClassPathResource, FileSystemResource, InputStreamResource, ServletContextResource, UrlResource

public abstract class AbstractResource
extends java.lang.Object
implements Resource

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.

Since:
28.12.2003
Author:
Juergen Hoeller

Field Summary
protected static java.lang.String URL_PROTOCOL_FILE
           
 
Constructor Summary
AbstractResource()
           
 
Method Summary
 boolean equals(java.lang.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.
 java.io.File getFile()
          This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
 java.net.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 implementations always returns false.
 java.lang.String toString()
          This implementation returns the description of this resource.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.core.io.Resource
getDescription
 
Methods inherited from interface org.springframework.core.io.InputStreamSource
getInputStream
 

Field Detail

URL_PROTOCOL_FILE

protected static final java.lang.String URL_PROTOCOL_FILE
See Also:
Constant Field Values
Constructor Detail

AbstractResource

public AbstractResource()
Method Detail

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.

Specified by:
exists in interface Resource

isOpen

public boolean isOpen()
This implementations always returns false.

Specified by:
isOpen in interface Resource

getURL

public java.net.URL getURL()
                    throws java.io.IOException
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.

Specified by:
getURL in interface Resource
Throws:
java.io.IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor

getFile

public java.io.File getFile()
                     throws java.io.IOException
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.

Specified by:
getFile in interface Resource
Throws:
java.io.IOException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system

toString

public java.lang.String toString()
This implementation returns the description of this resource.

See Also:
Resource.getDescription()

equals

public boolean equals(java.lang.Object obj)
This implementation compares description strings.

See Also:
Resource.getDescription()

hashCode

public int hashCode()
This implementation returns the description's hash code.

See Also:
Resource.getDescription()


Copyright (C) 2003-2004 The Spring Framework Project.