Top Description Fields Constructors Methods
org.springframework.core.io

public Class VfsResource

extends AbstractResource
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, java.net.URI, .URL, org.springframework.lang.Nullable, org.springframework.util.Assert, .ResourceUtils

JBoss VFS based 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+.

Authors
Ales Justin, Juergen Hoeller, Costin Leau, Sam Brannen
Since
3.0

Field Summary

Modifier and TypeField and Description
private final Object

Constructor Summary

AccessConstructor and Description
public
VfsResource(Object
a org.jboss.vfs.VirtualFile instance (untyped in order to avoid a static dependency on the VFS API)
resource
)

Create a new VfsResource wrapping the given resource handle.

Method Summary

Modifier and TypeMethod and Description
public long
contentLength()

Overrides org.springframework.core.io.AbstractResource.contentLength.

Implements org.springframework.core.io.Resource.contentLength.

This method reads the entire InputStream to determine the content length.
public Resource
createRelative(String
the relative path (relative to this resource)
relativePath
)

Overrides org.springframework.core.io.AbstractResource.createRelative.

Implements org.springframework.core.io.Resource.createRelative.

This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides org.springframework.core.io.AbstractResource.equals.

This implementation compares description strings.
public boolean
exists()

Overrides org.springframework.core.io.AbstractResource.exists.

Implements org.springframework.core.io.Resource.exists.

This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
public String
getDescription()

Implements org.springframework.core.io.Resource.getDescription.

Return a description for this resource, to be used for error output when working with the resource.
public File
getFile()

Overrides org.springframework.core.io.AbstractResource.getFile.

Implements org.springframework.core.io.Resource.getFile.

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
public String
getFilename()

Overrides org.springframework.core.io.AbstractResource.getFilename.

Implements org.springframework.core.io.Resource.getFilename.

This implementation always returns null, assuming that this resource type does not have a filename.
public InputStream
getInputStream()

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Return an InputStream for the content of an underlying resource.
public URI
getURI()

Overrides org.springframework.core.io.AbstractResource.getURI.

Implements org.springframework.core.io.Resource.getURI.

This implementation builds a URI based on the URL returned by getURL().
public URL
getURL()

Overrides org.springframework.core.io.AbstractResource.getURL.

Implements org.springframework.core.io.Resource.getURL.

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.
public int
hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the description's hash code.
public boolean
isReadable()

Overrides org.springframework.core.io.AbstractResource.isReadable.

Overrides default org.springframework.core.io.Resource.isReadable.

This implementation always returns true for a resource that exists (revised as of 5.1).
public long
lastModified()

Overrides org.springframework.core.io.AbstractResource.lastModified.

Implements org.springframework.core.io.Resource.lastModified.

This implementation checks the timestamp of the underlying File, if available.
Inherited from org.springframework.core.io.AbstractResource:
getFileForLastModifiedCheckisFileisOpenreadableChanneltoString

Field Detail

resourceback to summary
private final Object resource

Constructor Detail

VfsResourceback to summary
public VfsResource(Object resource)

Create a new VfsResource wrapping the given resource handle.

Parameters
resource:Object

a org.jboss.vfs.VirtualFile instance (untyped in order to avoid a static dependency on the VFS API)

Method Detail

contentLengthback to summary
public long contentLength() throws IOException

Overrides org.springframework.core.io.AbstractResource.contentLength.

Implements org.springframework.core.io.Resource.contentLength.

Doc from org.springframework.core.io.AbstractResource.contentLength.

This method reads the entire InputStream to determine the content length.

For a custom subclass 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.

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.Resource.contentLength.

if the resource cannot be resolved (in the file system or as some other known physical resource type)

createRelativeback to summary
public Resource createRelative(String relativePath) throws IOException

Overrides org.springframework.core.io.AbstractResource.createRelative.

Implements org.springframework.core.io.Resource.createRelative.

Doc from org.springframework.core.io.AbstractResource.createRelative.

This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.

Parameters
relativePath:String

Doc from org.springframework.core.io.Resource.createRelative.

the relative path (relative to this resource)

Returns:Resource

Doc from org.springframework.core.io.Resource.createRelative.

the resource handle for the relative resource

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.Resource.createRelative.

if the relative resource cannot be determined

equalsback to summary
public boolean equals(Object other)

Overrides org.springframework.core.io.AbstractResource.equals.

Doc from org.springframework.core.io.AbstractResource.equals.

This implementation compares description strings.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
existsback to summary
public boolean exists()

Overrides org.springframework.core.io.AbstractResource.exists.

Implements org.springframework.core.io.Resource.exists.

Doc from org.springframework.core.io.AbstractResource.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.

Annotations
@Override
getDescriptionback to summary
public String getDescription()

Implements org.springframework.core.io.Resource.getDescription.

Doc from org.springframework.core.io.Resource.getDescription.

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.

Annotations
@Override
getFileback to summary
public File getFile() throws IOException

Overrides org.springframework.core.io.AbstractResource.getFile.

Implements org.springframework.core.io.Resource.getFile.

Doc from org.springframework.core.io.AbstractResource.getFile.

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.Resource.getFile.

in case of general resolution/reading failures

getFilenameback to summary
public String getFilename()

Overrides org.springframework.core.io.AbstractResource.getFilename.

Implements org.springframework.core.io.Resource.getFilename.

Doc from org.springframework.core.io.AbstractResource.getFilename.

This implementation always returns null, assuming that this resource type does not have a filename.

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

Return an InputStream 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:InputStream

the input stream for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:
if the content stream could not be opened
getURIback to summary
public URI getURI() throws IOException

Overrides org.springframework.core.io.AbstractResource.getURI.

Implements org.springframework.core.io.Resource.getURI.

Doc from org.springframework.core.io.AbstractResource.getURI.

This implementation builds a URI based on the URL returned by getURL().

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.Resource.getURI.

if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor

getURLback to summary
public URL getURL() throws IOException

Overrides org.springframework.core.io.AbstractResource.getURL.

Implements org.springframework.core.io.Resource.getURL.

Doc from org.springframework.core.io.AbstractResource.getURL.

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.Resource.getURL.

if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor

hashCodeback to summary
public int hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

Doc from org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the description's hash code.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
isReadableback to summary
public boolean isReadable()

Overrides org.springframework.core.io.AbstractResource.isReadable.

Overrides default org.springframework.core.io.Resource.isReadable.

Doc from org.springframework.core.io.AbstractResource.isReadable.

This implementation always returns true for a resource that exists (revised as of 5.1).

Annotations
@Override
lastModifiedback to summary
public long lastModified() throws IOException

Overrides org.springframework.core.io.AbstractResource.lastModified.

Implements org.springframework.core.io.Resource.lastModified.

Doc from org.springframework.core.io.AbstractResource.lastModified.

This implementation checks the timestamp of the underlying File, if available.

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.Resource.lastModified.

if the resource cannot be resolved (in the file system or as some other known physical resource type)