Class FileUrlResource
- All Implemented Interfaces:
- InputStreamSource,- Resource,- WritableResource
UrlResource which assumes file resolution, to the degree
 of implementing the WritableResource interface for it. This resource
 variant also caches resolved File handles from getFile().
 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
 or NIO Path, consider using FileSystemResource.
- Since:
- 5.0.2
- Author:
- Juergen Hoeller
- 
Constructor SummaryConstructorsConstructorDescriptionFileUrlResource(String location) Create a newFileUrlResourcebased on the given file location, using the URL protocol "file".FileUrlResource(URL url) Create a newFileUrlResourcebased on the given URL object.
- 
Method SummaryModifier and TypeMethodDescriptioncreateRelative(String relativePath) This implementation creates aUrlResource, delegating toUrlResource.createRelativeURL(String)for adapting the relative path.getFile()This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.Return anOutputStreamfor the underlying resource, allowing to (over-)write its content.booleanIndicate whether the contents of this resource can be written viaWritableResource.getOutputStream().Return aWritableByteChannel.Methods inherited from class org.springframework.core.io.UrlResourcecreateRelativeURL, customizeConnection, equals, from, from, getDescription, getFilename, getInputStream, getURI, getURL, hashCode, isFileMethods inherited from class org.springframework.core.io.AbstractFileResolvingResourcecontentLength, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannelMethods inherited from class org.springframework.core.io.AbstractResourceisOpen, 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.ResourcecontentLength, exists, getContentAsByteArray, getContentAsString, getDescription, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel
- 
Constructor Details- 
FileUrlResourceCreate a newFileUrlResourcebased 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, it is acceptable for this purpose. - Parameters:
- url- a URL
- See Also:
 
- 
FileUrlResourceCreate a newFileUrlResourcebased on the given file location, using the URL protocol "file".The given parts will automatically get encoded if necessary. - Parameters:
- location- the location (i.e. the file path within that protocol)
- Throws:
- MalformedURLException- if the given URL specification is not valid
- See Also:
 
 
- 
- 
Method Details- 
getFileDescription copied from class:UrlResourceThis implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.- Specified by:
- getFilein interface- Resource
- Overrides:
- getFilein class- UrlResource
- 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:
 
- 
isWritablepublic boolean isWritable()Description copied from interface:WritableResourceIndicate whether the contents of this resource can be written viaWritableResource.getOutputStream().Will be truefor typical resource descriptors; note that actual content writing may still fail when attempted. However, a value offalseis a definitive indication that the resource content cannot be modified.- Specified by:
- isWritablein interface- WritableResource
- See Also:
 
- 
getOutputStreamDescription copied from interface:WritableResourceReturn anOutputStreamfor the underlying resource, allowing to (over-)write its content.- Specified by:
- getOutputStreamin interface- WritableResource
- Throws:
- IOException- if the stream could not be opened
- See Also:
 
- 
writableChannelDescription copied from interface:WritableResourceReturn aWritableByteChannel.It is expected that each call creates a fresh channel. The default implementation returns Channels.newChannel(OutputStream)with the result ofWritableResource.getOutputStream().- Specified by:
- writableChannelin interface- WritableResource
- 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
- See Also:
 
- 
createRelativeDescription copied from class:UrlResourceThis implementation creates aUrlResource, delegating toUrlResource.createRelativeURL(String)for adapting the relative path.- Specified by:
- createRelativein interface- Resource
- Overrides:
- createRelativein class- UrlResource
- Parameters:
- relativePath- the relative path (relative to this resource)
- Returns:
- the resource handle for the relative resource
- Throws:
- MalformedURLException
- See Also:
 
 
-