类 FileUrlResource
- java.lang.Object
-
- com.alibaba.nacos.common.packagescan.resource.AbstractResource
-
- com.alibaba.nacos.common.packagescan.resource.AbstractFileResolvingResource
-
- com.alibaba.nacos.common.packagescan.resource.UrlResource
-
- com.alibaba.nacos.common.packagescan.resource.FileUrlResource
-
- 所有已实现的接口:
InputStreamSource,Resource,WritableResource
public class FileUrlResource extends UrlResource implements WritableResource
Copy from https://github.com/spring-projects/spring-framework.git, with less modifications 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
-
-
字段概要
字段 修饰符和类型 字段 说明 private java.io.Filefile
-
构造器概要
构造器 构造器 说明 FileUrlResource(java.lang.String location)Create a newFileUrlResourcebased on the given file location, using the URL protocol "file".FileUrlResource(java.net.URL url)Create a newFileUrlResourcebased on the given URL object.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ResourcecreateRelative(java.lang.String relativePath)This implementation creates aUrlResource, delegating toUrlResource.createRelativeUrl(String)for adapting the relative path.java.io.FilegetFile()This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.java.io.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().java.nio.channels.WritableByteChannelwritableChannel()Return aWritableByteChannel.-
从类继承的方法 com.alibaba.nacos.common.packagescan.resource.UrlResource
createRelativeUrl, equals, getDescription, getFilename, getInputStream, getUri, getUrl, hashCode, isFile
-
从类继承的方法 com.alibaba.nacos.common.packagescan.resource.AbstractFileResolvingResource
checkReadable, contentLength, customizeConnection, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannel
-
从类继承的方法 com.alibaba.nacos.common.packagescan.resource.AbstractResource
isOpen, toString
-
从接口继承的方法 com.alibaba.nacos.common.packagescan.resource.InputStreamSource
getInputStream
-
从接口继承的方法 com.alibaba.nacos.common.packagescan.resource.Resource
contentLength, exists, getDescription, getFilename, getUri, getUrl, isFile, isOpen, isReadable, lastModified, readableChannel
-
-
-
-
构造器详细资料
-
FileUrlResource
public FileUrlResource(java.net.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(java.lang.String location) throws java.net.MalformedURLExceptionCreate 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)- 抛出:
java.net.MalformedURLException- if the given URL specification is not valid- 另请参阅:
UrlResource(String, String),ResourceUtils.URL_PROTOCOL_FILE
-
-
方法详细资料
-
getFile
public java.io.File getFile() throws java.io.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- 抛出:
java.io.FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemjava.io.IOException- in case of general resolution/reading failures- 另请参阅:
ResourceUtils.getFile(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 java.io.OutputStream getOutputStream() throws java.io.IOException从接口复制的说明:WritableResourceReturn anOutputStreamfor the underlying resource, allowing to (over-)write its content.- 指定者:
getOutputStream在接口中WritableResource- 抛出:
java.io.IOException- if the stream could not be opened- 另请参阅:
InputStreamSource.getInputStream()
-
writableChannel
public java.nio.channels.WritableByteChannel writableChannel() throws java.io.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) - 抛出:
java.io.FileNotFoundException- if the underlying resource doesn't existjava.io.IOException- if the content channel could not be opened- 另请参阅:
WritableResource.getOutputStream()
-
createRelative
public Resource createRelative(java.lang.String relativePath) throws java.net.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
- 抛出:
java.net.MalformedURLException- 另请参阅:
UrlResource.createRelativeUrl(String)
-
-