Package org.springframework.core.io
Class AbstractFileResolvingResource
java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.AbstractFileResolvingResource
- All Implemented Interfaces:
- InputStreamSource,- Resource
- Direct Known Subclasses:
- ClassPathResource,- ServletContextResource,- UrlResource
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.
- Since:
- 3.0
- Author:
- Juergen Hoeller
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionlongThis method reads the entire InputStream to determine the content length.protected voidCustomize the givenHttpURLConnectionbefore fetching the resource.protected voidCustomize the givenURLConnectionbefore fetching the resource.booleanexists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.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 FileThis implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.protected FileThis implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).booleanisFile()This implementation always returnsfalse.protected booleanDetermine whether the givenURIrepresents a file in a file system.booleanThis implementation always returnstruefor a resource thatexists(revised as of 5.1).longThis implementation checks the timestamp of the underlying File, if available.This implementation returns a FileChannel for the given URI-identified resource, provided that it refers to a file in the file system.Methods inherited from class org.springframework.core.io.AbstractResourcecreateRelative, equals, getFilename, getURI, getURL, hashCode, isOpen, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.InputStreamSourcegetInputStreamMethods inherited from interface org.springframework.core.io.ResourcegetContentAsByteArray, getContentAsString, getDescription
- 
Constructor Details- 
AbstractFileResolvingResourcepublic AbstractFileResolvingResource()
 
- 
- 
Method Details- 
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:
 
- 
isFilepublic boolean isFile()Description copied from class:AbstractResourceThis implementation always returnsfalse.- Specified by:
- isFilein interface- Resource
- Overrides:
- isFilein class- AbstractResource
- See Also:
 
- 
getFileThis implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.- 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:
 
- 
getFileForLastModifiedCheckThis implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).- Overrides:
- getFileForLastModifiedCheckin class- AbstractResource
- Returns:
- the File to use for timestamp checking (never null)
- Throws:
- FileNotFoundException- if the resource cannot be resolved as an absolute file path, i.e. is not available in a file system
- IOException- in case of general resolution/reading failures
 
- 
isFileDetermine whether the givenURIrepresents a file in a file system.- Since:
- 5.0
- See Also:
 
- 
getFileThis implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.- Throws:
- IOException
- See Also:
 
- 
readableChannelThis implementation returns a FileChannel for the given URI-identified resource, provided that it refers to a file in the file system.- Specified by:
- readableChannelin interface- Resource
- Overrides:
- readableChannelin class- AbstractResource
- Returns:
- the byte channel for the underlying resource (must not be null)
- Throws:
- FileNotFoundException- if the underlying resource doesn't exist
- IOException- if the content channel could not be opened
- Since:
- 5.0
- See Also:
 
- 
contentLengthDescription copied from class:AbstractResourceThis 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.- 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:
 
- 
customizeConnectionCustomize the givenURLConnectionbefore fetching the resource.Calls ResourceUtils.useCachesIfNecessary(URLConnection)and delegates tocustomizeConnection(HttpURLConnection)if possible. Can be overridden in subclasses.- Parameters:
- con- the URLConnection to customize
- Throws:
- IOException- if thrown from URLConnection methods
 
- 
customizeConnectionCustomize the givenHttpURLConnectionbefore fetching the resource.Can be overridden in subclasses for configuring request headers and timeouts. - Parameters:
- con- the HttpURLConnection to customize
- Throws:
- IOException- if thrown from HttpURLConnection methods
 
 
-