Package org.springframework.core.io
Class VfsResource
- java.lang.Object
- org.springframework.core.io.AbstractResource
- org.springframework.core.io.VfsResource
- All Implemented Interfaces:
InputStreamSource
,Resource
public class VfsResource extends AbstractResource
JBoss VFS basedResource
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
- See Also:
org.jboss.vfs.VirtualFile
Constructor Summary
Constructors Constructor Description VfsResource(Object resource)
Create a newVfsResource
wrapping the given resource handle.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
contentLength()
This implementation reads the entire InputStream to calculate 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 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.String
getDescription()
Return a description for this resource, to be used for error output when working with the resource.File
getFile()
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.String
getFilename()
This implementation always returnsnull
, assuming that this resource type does not have a filename.InputStream
getInputStream()
Return anInputStream
for the content of an underlying resource.URI
getURI()
This implementation builds a URI based on the URL returned byAbstractResource.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
isReadable()
This implementation always returnstrue
.long
lastModified()
This implementation checks the timestamp of the underlying File, if available.Methods inherited from class org.springframework.core.io.AbstractResource
getFileForLastModifiedCheck, isOpen, toString
Constructor Detail
VfsResource
public VfsResource(Object resource)
Create a newVfsResource
wrapping the given resource handle.- Parameters:
resource
- aorg.jboss.vfs.VirtualFile
instance (untyped in order to avoid a static dependency on the VFS API)
Method Detail
getInputStream
public InputStream getInputStream() throws IOException
Description copied from interface:InputStreamSource
Return anInputStream
for 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 doesn't existIOException
- if the content stream could not be opened
exists
public boolean exists()
Description copied from class:AbstractResource
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 interfaceResource
- Overrides:
exists
in classAbstractResource
isReadable
public boolean isReadable()
Description copied from class:AbstractResource
This implementation always returnstrue
.- Specified by:
isReadable
in interfaceResource
- Overrides:
isReadable
in classAbstractResource
- See Also:
InputStreamSource.getInputStream()
getURL
public URL getURL() throws IOException
Description copied from class:AbstractResource
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.- Specified by:
getURL
in interfaceResource
- Overrides:
getURL
in classAbstractResource
- Throws:
IOException
- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
getURI
public URI getURI() throws IOException
Description copied from class:AbstractResource
This implementation builds a URI based on the URL returned byAbstractResource.getURL()
.- Specified by:
getURI
in interfaceResource
- Overrides:
getURI
in classAbstractResource
- Throws:
IOException
- if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
getFile
public File getFile() throws IOException
Description copied from class:AbstractResource
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.- Specified by:
getFile
in interfaceResource
- Overrides:
getFile
in classAbstractResource
- Throws:
FileNotFoundException
- 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 failures- See Also:
InputStreamSource.getInputStream()
contentLength
public long contentLength() throws IOException
Description copied from class:AbstractResource
This implementation reads the entire InputStream to calculate the content length. Subclasses will almost always be able to provide a more optimal version of this, e.g. checking a File length.- Specified by:
contentLength
in interfaceResource
- Overrides:
contentLength
in classAbstractResource
- Throws:
IOException
- if the resource cannot be resolved (in the file system or as some other known physical resource type)- See Also:
InputStreamSource.getInputStream()
lastModified
public long lastModified() throws IOException
Description copied from class:AbstractResource
This implementation checks the timestamp of the underlying File, if available.- Specified by:
lastModified
in interfaceResource
- Overrides:
lastModified
in classAbstractResource
- Throws:
IOException
- if the resource cannot be resolved (in the file system or as some other known physical resource type)- See Also:
AbstractResource.getFileForLastModifiedCheck()
createRelative
public Resource createRelative(String relativePath) throws IOException
Description copied from class:AbstractResource
This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.- Specified by:
createRelative
in interfaceResource
- Overrides:
createRelative
in classAbstractResource
- 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
getFilename
public String getFilename()
Description copied from class:AbstractResource
This implementation always returnsnull
, assuming that this resource type does not have a filename.- Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
getDescription
public String getDescription()
Description copied from interface:Resource
Return 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
toString
method.- See Also:
Object.toString()
equals
public boolean equals(Object obj)
Description copied from class:AbstractResource
This implementation compares description strings.- Overrides:
equals
in classAbstractResource
- See Also:
Resource.getDescription()
hashCode
public int hashCode()
Description copied from class:AbstractResource
This implementation returns the description's hash code.- Overrides:
hashCode
in classAbstractResource
- See Also:
Resource.getDescription()