Package org.springframework.core.io
Class AbstractResource
java.lang.Object
org.springframework.core.io.AbstractResource
- All Implemented Interfaces:
- InputStreamSource,- Resource
- Direct Known Subclasses:
- AbstractFileResolvingResource,- ByteArrayResource,- DescriptiveResource,- FileSystemResource,- InputStreamResource,- PathResource,- VfsResource
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, Sam Brannen
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionlongThis method reads the entire InputStream to determine the content length.createRelative(String relativePath) This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.booleanThis implementation compares description strings.booleanexists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.getFile()This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.protected FileDetermine the File to use for timestamp checking.This implementation always returnsnull, assuming that this resource type does not have a filename.getURI()This implementation builds a URI based on the URL returned bygetURL().getURL()This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.inthashCode()This implementation returns the description's hash code.booleanisFile()This implementation always returnsfalse.booleanisOpen()This implementation always returnsfalse.booleanThis implementation always returnstruefor a resource thatexists(revised as of 5.1).longThis implementation checks the timestamp of the underlying File, if available.This implementation returnsChannels.newChannel(InputStream)with the result ofInputStreamSource.getInputStream().toString()This implementation returns the description of this resource.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.InputStreamSourcegetInputStreamMethods inherited from interface org.springframework.core.io.ResourcegetDescription
- 
Constructor Details- 
AbstractResourcepublic AbstractResource()
 
- 
- 
Method Details- 
existspublic 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.
- 
isReadablepublic boolean isReadable()This implementation always returnstruefor a resource thatexists(revised as of 5.1).- Specified by:
- isReadablein interface- Resource
- See Also:
 
- 
isOpenpublic boolean isOpen()This implementation always returnsfalse.
- 
isFilepublic boolean isFile()This implementation always returnsfalse.
- 
getURLThis implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.- Specified by:
- getURLin interface- Resource
- Throws:
- IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
 
- 
getURIThis implementation builds a URI based on the URL returned bygetURL().- Specified by:
- getURIin interface- Resource
- Throws:
- IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
 
- 
getFileThis implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.- Specified by:
- getFilein interface- Resource
- Throws:
- FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
- IOException- in case of general resolution/reading failures
- See Also:
 
- 
readableChannelThis implementation returnsChannels.newChannel(InputStream)with the result ofInputStreamSource.getInputStream().This is the same as in Resource's corresponding default method but mirrored here for efficient JVM-level dispatching in a class hierarchy.- Specified by:
- readableChannelin interface- Resource
- Returns:
- the byte channel for the underlying resource (must not be null)
- Throws:
- FileNotFoundException- if the underlying resource doesn't exist
- IOException- if the content channel could not be opened
- See Also:
 
- 
contentLengthThis method reads the entire InputStream to determine the content length.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.- Specified by:
- contentLengthin interface- Resource
- Throws:
- IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
- See Also:
 
- 
lastModifiedThis implementation checks the timestamp of the underlying File, if available.- Specified by:
- lastModifiedin interface- Resource
- Throws:
- IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
- See Also:
 
- 
getFileForLastModifiedCheckDetermine the File to use for timestamp checking.The default implementation delegates to getFile().- Returns:
- the File to use for timestamp checking (never null)
- Throws:
- FileNotFoundException- if the resource cannot be resolved as an absolute file path, i.e. is not available in a file system
- IOException- in case of general resolution/reading failures
 
- 
createRelativeThis implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.- Specified by:
- createRelativein interface- Resource
- Parameters:
- relativePath- the relative path (relative to this resource)
- Returns:
- the resource handle for the relative resource
- Throws:
- IOException- if the relative resource cannot be determined
 
- 
getFilenameThis implementation always returnsnull, assuming that this resource type does not have a filename.- Specified by:
- getFilenamein interface- Resource
 
- 
equalsThis implementation compares description strings.
- 
hashCodepublic int hashCode()This implementation returns the description's hash code.
- 
toStringThis implementation returns the description of this resource.
 
-