类 FileUrlResource
- java.lang.Object
- org.springframework.core.io.AbstractResource
- org.springframework.core.io.AbstractFileResolvingResource
- org.springframework.core.io.UrlResource
- org.springframework.core.io.FileUrlResource
- 所有已实现的接口:
InputStreamSource,Resource,WritableResource
public class FileUrlResource extends UrlResource implements WritableResource
Subclass ofUrlResourcewhich assumes file resolution, to the degree of implementing theWritableResourceinterface for it. This resource variant also caches resolvedFilehandles fromgetFile().This is the class resolved by
DefaultResourceLoaderfor a "file:..." URL location, allowing a downcast toWritableResourcefor it.Alternatively, for direct construction from a
Filehandle or NIOPath, consider usingFileSystemResource.- 从以下版本开始:
- 5.0.2
- 作者:
- Juergen Hoeller
构造器概要
构造器 构造器 说明 FileUrlResource(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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ResourcecreateRelative(String relativePath)This implementation creates aUrlResource, delegating toUrlResource.createRelativeURL(String)for adapting the relative path.FilegetFile()This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.OutputStreamgetOutputStream()Return anOutputStreamfor the underlying resource, allowing to (over-)write its content.booleanisWritable()Indicate whether the contents of this resource can be written viaWritableResource.getOutputStream().WritableByteChannelwritableChannel()Return aWritableByteChannel.从类继承的方法 org.springframework.core.io.UrlResource
createRelativeURL, equals, getDescription, getFilename, getInputStream, getURI, getURL, hashCode, isFile
从类继承的方法 org.springframework.core.io.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannel
从类继承的方法 org.springframework.core.io.AbstractResource
isOpen, toString
从接口继承的方法 org.springframework.core.io.InputStreamSource
getInputStream
从接口继承的方法 org.springframework.core.io.Resource
contentLength, exists, getDescription, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel
构造器详细资料
FileUrlResource
public FileUrlResource(URL url)
Create 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.
- 参数:
url- a URL- 另请参阅:
ResourceUtils.isFileURL(URL),getFile()
FileUrlResource
public FileUrlResource(String location) throws MalformedURLException
Create a newFileUrlResourcebased 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)- 抛出:
MalformedURLException- if the given URL specification is not valid- 另请参阅:
UrlResource(String, String),ResourceUtils.URL_PROTOCOL_FILE
方法详细资料
getFile
public File getFile() throws IOException
从类复制的说明:UrlResourceThis implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.- 指定者:
getFile在接口中Resource- 覆盖:
getFile在类中UrlResource- 抛出:
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 failures- 另请参阅:
ResourceUtils.getFile(java.net.URL, String)
isWritable
public boolean isWritable()
从接口复制的说明: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.
getOutputStream
public OutputStream getOutputStream() throws IOException
从接口复制的说明:WritableResourceReturn anOutputStreamfor the underlying resource, allowing to (over-)write its content.- 指定者:
getOutputStream在接口中WritableResource- 抛出:
IOException- if the stream could not be opened- 另请参阅:
InputStreamSource.getInputStream()
writableChannel
public WritableByteChannel writableChannel() throws IOException
从接口复制的说明:WritableResourceReturn aWritableByteChannel.It is expected that each call creates a fresh channel.
The default implementation returns
Channels.newChannel(OutputStream)with the result ofWritableResource.getOutputStream().- 指定者:
writableChannel在接口中WritableResource- 返回:
- the byte channel for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource doesn't existIOException- if the content channel could not be opened- 另请参阅:
WritableResource.getOutputStream()
createRelative
public Resource createRelative(String relativePath) throws MalformedURLException
从类复制的说明:UrlResourceThis implementation creates aUrlResource, delegating toUrlResource.createRelativeURL(String)for adapting the relative path.- 指定者:
createRelative在接口中Resource- 覆盖:
createRelative在类中UrlResource- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 抛出:
MalformedURLException- 另请参阅:
UrlResource.createRelativeURL(String)