Spring Framework

org.springframework.core.io
Class VfsResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
      extended by org.springframework.core.io.VfsResource
All Implemented Interfaces:
InputStreamSource, Resource

public class VfsResource
extends AbstractResource

VFS based Resource implementation. Supports the corresponding VFS API versions on JBoss AS 5.x as well as 6.x and 7.x.

Since:
3.0
Author:
Ales Justin, Juergen Hoeller, Costin Leau
See Also:
org.jboss.virtual.VirtualFile, org.jboss.vfs.VirtualFile

Constructor Summary
VfsResource(java.lang.Object resources)
           
 
Method Summary
 long contentLength()
          This implementation reads the entire InputStream to calculate the content length.
 Resource createRelative(java.lang.String relativePath)
          This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
 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.lang.String getDescription()
          Return a description for this resource, to be used for error output when working with the resource.
 java.io.File getFile()
          This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
 java.lang.String getFilename()
          This implementation always returns null, assuming that this resource type does not have a filename.
 java.io.InputStream getInputStream()
          Return an InputStream.
 java.net.URI getURI()
          This implementation builds a URI based on the URL returned by AbstractResource.getURL().
 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 isReadable()
          This implementation always returns true.
 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VfsResource

public VfsResource(java.lang.Object resources)
Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from interface: Resource
Return an InputStream.

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:
java.io.IOException - if the stream could not be opened
See Also:
MimeMessageHelper.addAttachment(String, InputStreamSource)

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 interface Resource
Overrides:
exists in class AbstractResource

isReadable

public boolean isReadable()
Description copied from class: AbstractResource
This implementation always returns true.

Specified by:
isReadable in interface Resource
Overrides:
isReadable in class AbstractResource
See Also:
Resource.getInputStream()

getURL

public java.net.URL getURL()
                    throws java.io.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 interface Resource
Overrides:
getURL in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor

getURI

public java.net.URI getURI()
                    throws java.io.IOException
Description copied from class: AbstractResource
This implementation builds a URI based on the URL returned by AbstractResource.getURL().

Specified by:
getURI in interface Resource
Overrides:
getURI in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor

getFile

public java.io.File getFile()
                     throws java.io.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 interface Resource
Overrides:
getFile in class AbstractResource
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

contentLength

public long contentLength()
                   throws java.io.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 interface Resource
Overrides:
contentLength in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
See Also:
Resource.getInputStream()

lastModified

public long lastModified()
                  throws java.io.IOException
Description copied from class: AbstractResource
This implementation checks the timestamp of the underlying File, if available.

Specified by:
lastModified in interface Resource
Overrides:
lastModified in class AbstractResource
Throws:
java.io.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(java.lang.String relativePath)
                        throws java.io.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 interface Resource
Overrides:
createRelative in class AbstractResource
Parameters:
relativePath - the relative path (relative to this resource)
Returns:
the resource handle for the relative resource
Throws:
java.io.IOException - if the relative resource cannot be determined

getFilename

public java.lang.String getFilename()
Description copied from class: AbstractResource
This implementation always returns null, assuming that this resource type does not have a filename.

Specified by:
getFilename in interface Resource
Overrides:
getFilename in class AbstractResource

getDescription

public java.lang.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(java.lang.Object obj)
Description copied from class: AbstractResource
This implementation compares description strings.

Overrides:
equals in class AbstractResource
See Also:
Resource.getDescription()

hashCode

public int hashCode()
Description copied from class: AbstractResource
This implementation returns the description's hash code.

Overrides:
hashCode in class AbstractResource
See Also:
Resource.getDescription()

Spring Framework