Class VfsResource
- All Implemented Interfaces:
- InputStreamSource,- Resource
Resource implementation.
 As of Spring 4.0, this class supports VFS 3.x on JBoss AS 6+
 (package org.jboss.vfs) and is in particular compatible with
 JBoss AS 7 and WildFly 8+.
- Since:
- 3.0
- Author:
- Ales Justin, Juergen Hoeller, Costin Leau, Sam Brannen
- 
Constructor SummaryConstructorsConstructorDescriptionVfsResource(Object resource) Create a newVfsResourcewrapping the given resource handle.
- 
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.Return a description for this resource, to be used for error output when working with the resource.getFile()This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.This implementation always returnsnull, assuming that this resource type does not have a filename.Return anInputStreamfor the content of an underlying resource.getURI()This implementation builds a URI based on the URL returned byAbstractResource.getURL().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.booleanThis implementation always returnstruefor a resource thatexists(revised as of 5.1).longThis implementation checks the timestamp of the underlying File, if available.Methods inherited from class org.springframework.core.io.AbstractResourcegetFileForLastModifiedCheck, isFile, isOpen, readableChannel, toString
- 
Constructor Details- 
VfsResourceCreate a newVfsResourcewrapping the given resource handle.- Parameters:
- resource- a- org.jboss.vfs.VirtualFileinstance (untyped in order to avoid a static dependency on the VFS API)
 
 
- 
- 
Method Details- 
getInputStreamDescription copied from interface:InputStreamSourceReturn anInputStreamfor 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.- Returns:
- the input stream for the underlying resource (must not be null)
- Throws:
- FileNotFoundException- if the underlying resource does not exist
- IOException- if the content stream could not be opened
- See Also:
 
- 
existspublic boolean exists()Description copied from class:AbstractResourceThis 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:
- existsin interface- Resource
- Overrides:
- existsin class- AbstractResource
 
- 
isReadablepublic boolean isReadable()Description copied from class:AbstractResourceThis implementation always returnstruefor a resource thatexists(revised as of 5.1).- Specified by:
- isReadablein interface- Resource
- Overrides:
- isReadablein class- AbstractResource
- See Also:
 
- 
getURLDescription copied from class:AbstractResourceThis implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.- Specified by:
- getURLin interface- Resource
- Overrides:
- getURLin class- AbstractResource
- Throws:
- IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
 
- 
getURIDescription copied from class:AbstractResourceThis implementation builds a URI based on the URL returned byAbstractResource.getURL().- Specified by:
- getURIin interface- Resource
- Overrides:
- getURIin class- AbstractResource
- Throws:
- IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
 
- 
getFileDescription copied from class:AbstractResourceThis implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.- Specified by:
- getFilein interface- Resource
- Overrides:
- getFilein class- AbstractResource
- 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:
 
- 
contentLengthDescription copied from class:AbstractResourceThis 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
- Overrides:
- contentLengthin class- AbstractResource
- Throws:
- IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
- See Also:
 
- 
lastModifiedDescription copied from class:AbstractResourceThis implementation checks the timestamp of the underlying File, if available.- Specified by:
- lastModifiedin interface- Resource
- Overrides:
- lastModifiedin class- AbstractResource
- Throws:
- IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
- See Also:
 
- 
createRelativeDescription copied from class:AbstractResourceThis implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.- Specified by:
- createRelativein interface- Resource
- Overrides:
- createRelativein class- AbstractResource
- 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
 
- 
getFilenameDescription copied from class:AbstractResourceThis implementation always returnsnull, assuming that this resource type does not have a filename.- Specified by:
- getFilenamein interface- Resource
- Overrides:
- getFilenamein class- AbstractResource
 
- 
getDescriptionDescription copied from interface:ResourceReturn a description for this resource, to be used for error output when working with the resource.Implementations are also encouraged to return this value from their toStringmethod.- See Also:
 
- 
equalsDescription copied from class:AbstractResourceThis implementation compares description strings.- Overrides:
- equalsin class- AbstractResource
- See Also:
 
- 
hashCodepublic int hashCode()Description copied from class:AbstractResourceThis implementation returns the description's hash code.- Overrides:
- hashCodein class- AbstractResource
- See Also:
 
 
-