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

public abstract Class AbstractFileResolvingResource

extends AbstractResource
Class Inheritance
Known Direct Subclasses
org.springframework.core.io.ClassPathResource, org.springframework.core.io.UrlResource
Imports
java.io.File, .FileNotFoundException, .IOException, java.net.HttpURLConnection, .JarURLConnection, .URI, .URL, .URLConnection, java.nio.channels.FileChannel, .ReadableByteChannel, java.nio.file.NoSuchFileException, .StandardOpenOption, java.util.jar.JarEntry, org.springframework.util.ResourceUtils

Abstract base class for resources which resolve URLs into File references, such as UrlResource or ClassPathResource.

Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs, resolving file system references accordingly.

Author
Juergen Hoeller
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AbstractFileResolvingResource.VfsResourceDelegate

Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
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.

protected void
customizeConnection(URLConnection
the URLConnection to customize
con
)

Customize the given URLConnection before fetching the resource.

protected void
customizeConnection(HttpURLConnection
the HttpURLConnection to customize
con
)

Customize the given HttpURLConnection before fetching the resource.

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 File
getFile()

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

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

This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.

protected File
getFile(URI uri)

This implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.

protected File
getFileForLastModifiedCheck()

Overrides org.springframework.core.io.AbstractResource.getFileForLastModifiedCheck.

This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).

public boolean
isFile()

Overrides org.springframework.core.io.AbstractResource.isFile.

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

This implementation always returns false.

protected boolean
isFile(URI uri)

Determine whether the given URI represents a file in a file system.

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.

public ReadableByteChannel
readableChannel()

Overrides org.springframework.core.io.AbstractResource.readableChannel.

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

This implementation returns a FileChannel for the given URI-identified resource, provided that it refers to a file in the file system.

Inherited from org.springframework.core.io.AbstractResource:
createRelativeequalsgetFilenamegetURIgetURLhashCodeisOpentoString

Constructor Detail

AbstractFileResolvingResourceback to summary
public AbstractFileResolvingResource()

Method Detail

checkReadableback to summary
pack-priv boolean checkReadable(URL url)
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)

customizeConnectionback to summary
protected void customizeConnection(URLConnection con) throws IOException

Customize the given URLConnection before fetching the resource.

Calls ResourceUtils#useCachesIfNecessary(URLConnection) and delegates to customizeConnection(HttpURLConnection) if possible. Can be overridden in subclasses.

Parameters
con:URLConnection

the URLConnection to customize

Exceptions
IOException:
if thrown from URLConnection methods
customizeConnectionback to summary
protected void customizeConnection(HttpURLConnection con) throws IOException

Customize the given HttpURLConnection before fetching the resource.

Can be overridden in subclasses for configuring request headers and timeouts.

Parameters
con:HttpURLConnection

the HttpURLConnection to customize

Exceptions
IOException:
if thrown from HttpURLConnection methods
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
getFileback to summary
public File getFile() throws IOException

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

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

This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.

Annotations
@Override
Exceptions
IOException:

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

in case of general resolution/reading failures

See Also
org.springframework.util.ResourceUtils#getFile(java.net.URL, String)
getFileback to summary
protected File getFile(URI uri) throws IOException

This implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.

See Also
org.springframework.util.ResourceUtils#getFile(java.net.URI, String)
getFileForLastModifiedCheckback to summary
protected File getFileForLastModifiedCheck() throws IOException

Overrides org.springframework.core.io.AbstractResource.getFileForLastModifiedCheck.

This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).

Returns:File

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

the File to use for timestamp checking (never null)

Annotations
@Override
Exceptions
IOException:

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

in case of general resolution/reading failures

isFileback to summary
public boolean isFile()

Overrides org.springframework.core.io.AbstractResource.isFile.

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

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

This implementation always returns false.

Annotations
@Override
isFileback to summary
protected boolean isFile(URI uri)

Determine whether the given URI represents a file in a file system.

Since
5.0
See Also
getFile(URI)
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)

readableChannelback to summary
public ReadableByteChannel readableChannel() throws IOException

Overrides org.springframework.core.io.AbstractResource.readableChannel.

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

This implementation returns a FileChannel for the given URI-identified resource, provided that it refers to a file in the file system.

Returns:ReadableByteChannel

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

the byte channel for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:

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

if the content channel could not be opened

Since
5.0
See Also
getFile()
org.springframework.core.io back to summary

private Class AbstractFileResolvingResource.VfsResourceDelegate

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.core.io.AbstractFileResolvingResource.VfsResourceDelegate

Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Resource
public static Resource
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

VfsResourceDelegateback to summary
private VfsResourceDelegate()

Method Detail

getResourceback to summary
public static Resource getResource(URL url) throws IOException
getResourceback to summary
public static Resource getResource(URI uri) throws IOException