public class FileUrlResource extends UrlResource implements WritableResource
UrlResource which assumes file resolution, to the degree
of implementing the WritableResource interface for it.
This is the class resolved by DefaultResourceLoader for a "file:..."
URL location, allowing a downcast to WritableResource for it.
Alternatively, for direct construction from a File handle,
consider using FileSystemResource. For an NIO Path,
consider using PathResource instead.
| Constructor and Description |
|---|
FileUrlResource(java.lang.String location)
Create a new
FileUrlResource based on the given file location,
using the URL protocol "file". |
FileUrlResource(java.net.URL url)
Create a new
FileUrlResource based on the given URL object. |
| Modifier and Type | Method and Description |
|---|---|
Resource |
createRelative(java.lang.String relativePath)
This implementation creates a
UrlResource, applying the given path
relative to the path of the underlying URL of this resource descriptor. |
java.io.OutputStream |
getOutputStream()
Return an
OutputStream for the underlying resource,
allowing to (over-)write its content. |
boolean |
isWritable()
Indicate whether the contents of this resource can be written
via
WritableResource.getOutputStream(). |
java.nio.channels.WritableByteChannel |
writableChannel()
Return a
WritableByteChannel. |
equals, getDescription, getFile, getFilename, getInputStream, getURI, getURL, hashCode, isFilecontentLength, customizeConnection, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannelisOpen, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontentLength, exists, getDescription, getFile, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannelgetInputStreampublic FileUrlResource(java.net.URL url)
FileUrlResource based on the given URL object.
Note that this does not enforce "file" as URL protocol. If a protocol is known to be resolvable to a file,
url - a URLResourceUtils.isFileURL(URL),
UrlResource.getFile()public FileUrlResource(java.lang.String location)
throws java.net.MalformedURLException
FileUrlResource based on the given file location,
using the URL protocol "file".
The given parts will automatically get encoded if necessary.
location - the location (i.e. the file path within that protocol)java.net.MalformedURLException - if the given URL specification is not validUrlResource.UrlResource(String, String),
ResourceUtils.URL_PROTOCOL_FILEpublic Resource createRelative(java.lang.String relativePath) throws java.net.MalformedURLException
UrlResourceUrlResource, applying the given path
relative to the path of the underlying URL of this resource descriptor.createRelative in interface ResourcecreateRelative in class UrlResourcerelativePath - the relative path (relative to this resource)java.net.MalformedURLExceptionURL.URL(java.net.URL, String)public boolean isWritable()
WritableResourceWritableResource.getOutputStream().
Will be true for typical resource descriptors;
note that actual content writing may still fail when attempted.
However, a value of false is a definitive indication
that the resource content cannot be modified.
isWritable in interface WritableResourceWritableResource.getOutputStream(),
Resource.isReadable()public java.io.OutputStream getOutputStream()
throws java.io.IOException
WritableResourceOutputStream for the underlying resource,
allowing to (over-)write its content.getOutputStream in interface WritableResourcejava.io.IOException - if the stream could not be openedInputStreamSource.getInputStream()public java.nio.channels.WritableByteChannel writableChannel()
throws java.io.IOException
WritableResourceWritableByteChannel.
It is expected that each call creates a fresh channel.
The default implementation returns Channels.newChannel(OutputStream)
with the result of WritableResource.getOutputStream().
writableChannel in interface WritableResourcenull)java.io.FileNotFoundException - if the underlying resource doesn't existjava.io.IOException - if the content channel could not be openedWritableResource.getOutputStream()