类 UrlResource
- java.lang.Object
-
- com.alibaba.nacos.common.packagescan.resource.AbstractResource
-
- com.alibaba.nacos.common.packagescan.resource.AbstractFileResolvingResource
-
- com.alibaba.nacos.common.packagescan.resource.UrlResource
-
- 所有已实现的接口:
InputStreamSource,Resource
- 直接已知子类:
FileUrlResource
public class UrlResource extends AbstractFileResolvingResource
Copy from https://github.com/spring-projects/spring-framework.git, with less modificationsResourceimplementation forjava.net.URLlocators. Supports resolution as aURLand also as aFilein case of the"file:"protocol.- 从以下版本开始:
- 28.12.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
URL
-
-
字段概要
字段 修饰符和类型 字段 说明 private java.net.URLcleanedUrlCleaned URL (with normalized path), used for comparisons.private java.net.URIuriOriginal URI, if available; used for URI and File access.private java.net.URLurlOriginal URL, used for actual access.
-
构造器概要
构造器 构造器 说明 UrlResource(java.lang.String path)Create a newUrlResourcebased on a URL path.UrlResource(java.lang.String protocol, java.lang.String location)Create a newUrlResourcebased on a URI specification.UrlResource(java.lang.String protocol, java.lang.String location, java.lang.String fragment)Create a newUrlResourcebased on a URI specification.UrlResource(java.net.URI uri)Create a newUrlResourcebased on the given URI object.UrlResource(java.net.URL url)Create a newUrlResourcebased on the given URL object.
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 ResourcecreateRelative(java.lang.String relativePath)This implementation creates aUrlResource, delegating tocreateRelativeUrl(String)for adapting the relative path.protected java.net.URLcreateRelativeUrl(java.lang.String relativePath)This delegate creates ajava.net.URL, applying the given path relative to the path of the underlying URL of this resource descriptor.booleanequals(java.lang.Object other)This implementation compares the underlying URL references.private java.net.URLgetCleanedUrl()Lazily determine a cleaned URL for the given original URL.private static java.net.URLgetCleanedUrl(java.net.URL originalUrl, java.lang.String originalPath)Determine a cleaned URL for the given original URL.java.lang.StringgetDescription()This implementation returns a description that includes the URL.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.lang.StringgetFilename()This implementation returns the name of the file that this URL refers to.java.io.InputStreamgetInputStream()This implementation opens an InputStream for the given URL.java.net.URIgetUri()This implementation returns the underlying URI directly, if possible.java.net.URLgetUrl()This implementation returns the underlying URL reference.inthashCode()This implementation returns the hash code of the underlying URL reference.booleanisFile()This implementation always returnsfalse.-
从类继承的方法 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
-
-
-
-
构造器详细资料
-
UrlResource
public UrlResource(java.net.URI uri) throws java.net.MalformedURLExceptionCreate a newUrlResourcebased on the given URI object.- 参数:
uri- a URI- 抛出:
java.net.MalformedURLException- if the given URL path is not valid- 从以下版本开始:
- 2.5
-
UrlResource
public UrlResource(java.net.URL url)
Create a newUrlResourcebased on the given URL object.- 参数:
url- a URL
-
UrlResource
public UrlResource(java.lang.String path) throws java.net.MalformedURLExceptionCreate a newUrlResourcebased on a URL path.Note: The given path needs to be pre-encoded if necessary.
- 参数:
path- a URL path- 抛出:
java.net.MalformedURLException- if the given URL path is not valid- 另请参阅:
URL(String)
-
UrlResource
public UrlResource(java.lang.String protocol, java.lang.String location) throws java.net.MalformedURLExceptionCreate a newUrlResourcebased on a URI specification.The given parts will automatically get encoded if necessary.
- 参数:
protocol- the URL protocol to use (e.g. "jar" or "file" - without colon); also known as "scheme"location- the location (e.g. the file path within that protocol); also known as "scheme-specific part"- 抛出:
java.net.MalformedURLException- if the given URL specification is not valid- 另请参阅:
URI(String, String, String)
-
UrlResource
public UrlResource(java.lang.String protocol, java.lang.String location, java.lang.String fragment) throws java.net.MalformedURLExceptionCreate a newUrlResourcebased on a URI specification.The given parts will automatically get encoded if necessary.
- 参数:
protocol- the URL protocol to use (e.g. "jar" or "file" - without colon); also known as "scheme"location- the location (e.g. the file path within that protocol); also known as "scheme-specific part"fragment- the fragment within that location (e.g. anchor on an HTML page, as following after a "#" separator)- 抛出:
java.net.MalformedURLException- if the given URL specification is not valid- 另请参阅:
URI(String, String, String)
-
-
方法详细资料
-
getCleanedUrl
private static java.net.URL getCleanedUrl(java.net.URL originalUrl, java.lang.String originalPath)Determine a cleaned URL for the given original URL.- 参数:
originalUrl- the original URLoriginalPath- the original URL path- 返回:
- the cleaned URL (possibly the original URL as-is)
- 另请参阅:
StringUtils.cleanPath(java.lang.String)
-
getCleanedUrl
private java.net.URL getCleanedUrl()
Lazily determine a cleaned URL for the given original URL.
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionThis implementation opens an InputStream for the given URL.It sets the
useCachesflag tofalse, mainly to avoid jar file locking on Windows.- 返回:
- the input stream for the underlying resource (must not be
null) - 抛出:
java.io.FileNotFoundException- if the underlying resource does not existjava.io.IOException- if the content stream could not be opened- 另请参阅:
URL.openConnection(),URLConnection.setUseCaches(boolean),URLConnection.getInputStream()
-
getUrl
public java.net.URL getUrl()
This implementation returns the underlying URL reference.- 指定者:
getUrl在接口中Resource- 覆盖:
getUrl在类中AbstractResource
-
getUri
public java.net.URI getUri() throws java.io.IOExceptionThis implementation returns the underlying URI directly, if possible.- 指定者:
getUri在接口中Resource- 覆盖:
getUri在类中AbstractResource- 抛出:
java.io.IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
-
isFile
public boolean isFile()
从类复制的说明:AbstractResourceThis implementation always returnsfalse.- 指定者:
isFile在接口中Resource- 覆盖:
isFile在类中AbstractFileResolvingResource- 另请参阅:
Resource.getFile()
-
getFile
public java.io.File getFile() throws java.io.IOExceptionThis implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.- 指定者:
getFile在接口中Resource- 覆盖:
getFile在类中AbstractFileResolvingResource- 抛出:
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)
-
createRelative
public Resource createRelative(java.lang.String relativePath) throws java.net.MalformedURLException
This implementation creates aUrlResource, delegating tocreateRelativeUrl(String)for adapting the relative path.- 指定者:
createRelative在接口中Resource- 覆盖:
createRelative在类中AbstractResource- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 抛出:
java.net.MalformedURLException- 另请参阅:
createRelativeUrl(String)
-
createRelativeUrl
protected java.net.URL createRelativeUrl(java.lang.String relativePath) throws java.net.MalformedURLExceptionThis delegate creates ajava.net.URL, applying the given path relative to the path of the underlying URL of this resource descriptor. A leading slash will get dropped; a "#" symbol will get encoded.- 抛出:
java.net.MalformedURLException- 从以下版本开始:
- 5.2
- 另请参阅:
createRelative(String)
-
getFilename
public java.lang.String getFilename()
This implementation returns the name of the file that this URL refers to.- 指定者:
getFilename在接口中Resource- 覆盖:
getFilename在类中AbstractResource- 另请参阅:
URL.getPath()
-
getDescription
public java.lang.String getDescription()
This implementation returns a description that includes the URL.- 另请参阅:
Object.toString()
-
equals
public boolean equals(java.lang.Object other)
This implementation compares the underlying URL references.- 覆盖:
equals在类中AbstractResource- 另请参阅:
Resource.getDescription()
-
hashCode
public int hashCode()
This implementation returns the hash code of the underlying URL reference.- 覆盖:
hashCode在类中AbstractResource- 另请参阅:
Resource.getDescription()
-
-