public abstract class AbstractFileResolvingResource extends AbstractResource
UrlResource
or ClassPathResource
.
Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs, resolving file system references accordingly.
Constructor and Description |
---|
AbstractFileResolvingResource() |
Modifier and Type | Method and Description |
---|---|
long |
contentLength()
This method reads the entire InputStream to determine the content length.
|
protected void |
customizeConnection(HttpURLConnection con)
Customize the given
HttpURLConnection before fetching the resource. |
protected void |
customizeConnection(URLConnection con)
Customize the given
URLConnection before fetching the resource. |
boolean |
exists()
This implementation checks whether a File can be opened,
falling back to whether an InputStream can be opened.
|
File |
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()
This implementation determines the underlying File
(or jar file, in case of a resource in a jar/zip).
|
boolean |
isFile()
This implementation always returns
false . |
protected boolean |
isFile(URI uri)
Determine whether the given
URI represents a file in a file system. |
boolean |
isReadable()
This implementation always returns
true for a resource
that exists (revised as of 5.1). |
long |
lastModified()
This implementation checks the timestamp of the underlying File,
if available.
|
ReadableByteChannel |
readableChannel()
This implementation returns a FileChannel for the given URI-identified
resource, provided that it refers to a file in the file system.
|
createRelative, equals, getFilename, getURI, getURL, hashCode, isOpen, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getDescription
getInputStream
public boolean exists()
AbstractResource
This will cover both directories and content resources.
exists
in interface Resource
exists
in class AbstractResource
public boolean isReadable()
AbstractResource
true
for a resource
that exists
(revised as of 5.1).isReadable
in interface Resource
isReadable
in class AbstractResource
InputStreamSource.getInputStream()
,
Resource.exists()
public boolean isFile()
AbstractResource
false
.isFile
in interface Resource
isFile
in class AbstractResource
Resource.getFile()
public File getFile() throws IOException
getFile
in interface Resource
getFile
in class AbstractResource
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 failuresResourceUtils.getFile(java.net.URL, String)
protected File getFileForLastModifiedCheck() throws IOException
getFileForLastModifiedCheck
in class AbstractResource
null
)FileNotFoundException
- if the resource cannot be resolved as
an absolute file path, i.e. is not available in a file systemIOException
- in case of general resolution/reading failuresprotected boolean isFile(URI uri)
URI
represents a file in a file system.getFile(URI)
protected File getFile(URI uri) throws IOException
IOException
ResourceUtils.getFile(java.net.URI, String)
public ReadableByteChannel readableChannel() throws IOException
readableChannel
in interface Resource
readableChannel
in class AbstractResource
null
)FileNotFoundException
- if the underlying resource doesn't existIOException
- if the content channel could not be openedgetFile()
public long contentLength() throws IOException
AbstractResource
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.
contentLength
in interface Resource
contentLength
in class AbstractResource
IOException
- if the resource cannot be resolved
(in the file system or as some other known physical resource type)InputStreamSource.getInputStream()
public long lastModified() throws IOException
AbstractResource
lastModified
in interface Resource
lastModified
in class AbstractResource
IOException
- if the resource cannot be resolved
(in the file system or as some other known physical resource type)AbstractResource.getFileForLastModifiedCheck()
protected void customizeConnection(URLConnection con) throws IOException
URLConnection
before fetching the resource.
Calls ResourceUtils.useCachesIfNecessary(URLConnection)
and
delegates to customizeConnection(HttpURLConnection)
if possible.
Can be overridden in subclasses.
con
- the URLConnection to customizeIOException
- if thrown from URLConnection methodsprotected void customizeConnection(HttpURLConnection con) throws IOException
HttpURLConnection
before fetching the resource.
Can be overridden in subclasses for configuring request headers and timeouts.
con
- the HttpURLConnection to customizeIOException
- if thrown from HttpURLConnection methods