类 UrlResource
- 所有已实现的接口:
InputStreamSource,Resource
- 直接已知子类:
FileUrlResource,JarEntryResource
Resource implementation for java.net.URL locators.
Supports resolution as a URL and also as a File in
case of the "file:" protocol.- 从以下版本开始:
- 2.1.6 2019-05-14 22:26
- 作者:
- TODAY
-
字段概要
从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器构造器说明UrlResource(String path) Create a newUrlBasedResourcebased on a URL path.UrlResource(String protocol, String location) Create a newUrlBasedResourcebased on a URI specification.UrlResource(String protocol, String location, String fragment) Create a newUrlBasedResourcebased on a URI specification.UrlResource(URI uri) Create a newUrlBasedResourcebased on the given URI object.UrlResource(URL url) Create a newUrlBasedResourcebased on the given URL object. -
方法概要
修饰符和类型方法说明createRelative(String relativePath) This implementation creates aUrlBasedResource, delegating tocreateRelativeURL(String)for adapting the relative path.protected URLcreateRelativeURL(String relativePath) This delegate creates ajava.net.URL, applying the given path relative to the path of the underlying URL of this resource descriptor.booleanThis implementation compares the underlying URL references.static UrlResourceCreate a newUrlResourcefrom the given URL path.static UrlResourceCreate a newUrlResourcefrom the givenURI.getFile()This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.This implementation opens an InputStream for the given URL.getName()This implementation returns the URL-decoded name of the file that this URL refers to.getURI()This implementation returns the underlying URI directly, if possible.getURL()This implementation returns the underlying URL reference.inthashCode()This implementation returns the hash code of the underlying URL reference.booleanisFile()This implementation always returnsfalse.toString()Return a description for this resource, to be used for error output when working with the resource.从类继承的方法 cn.taketoday.core.io.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannel从类继承的方法 cn.taketoday.core.io.AbstractResource
isDirectory, isOpen, list, list从接口继承的方法 cn.taketoday.core.io.InputStreamSource
getReader, getReader
-
构造器详细资料
-
UrlResource
Create a newUrlBasedResourcebased on the given URI object.- 参数:
uri- a URI- 抛出:
MalformedURLException- if the given URL path is not valid- 从以下版本开始:
- 4.0
-
UrlResource
Create a newUrlBasedResourcebased on the given URL object.- 参数:
url- a URL
-
UrlResource
Create a newUrlBasedResourcebased on a URL path.Note: The given path needs to be pre-encoded if necessary.
- 参数:
path- a URL path- 抛出:
MalformedURLException- if the given URL path is not valid- 从以下版本开始:
- 4.0
- 另请参阅:
-
UrlResource
Create a newUrlBasedResourcebased 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"- 抛出:
MalformedURLException- if the given URL specification is not valid- 从以下版本开始:
- 4.0
- 另请参阅:
-
UrlResource
public UrlResource(String protocol, String location, @Nullable String fragment) throws MalformedURLException Create a newUrlBasedResourcebased 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)- 抛出:
MalformedURLException- if the given URL specification is not valid- 从以下版本开始:
- 4.0
- 另请参阅:
-
-
方法详细资料
-
getInputStream
This implementation opens an InputStream for the given URL.It sets the
useCachesflag tofalse, mainly to avoid jar file locking on Windows.- 返回:
- input stream of
Resourcecontent - 抛出:
IOException- If an input exception occurs- 另请参阅:
-
getURL
This implementation returns the underlying URL reference.- 指定者:
getURL在接口中Resource- 覆盖:
getURL在类中AbstractResource
-
getURI
This implementation returns the underlying URI directly, if possible.- 指定者:
getURI在接口中Resource- 覆盖:
getURI在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
-
getFile
This 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- 抛出:
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- 另请参阅:
-
isFile
public boolean isFile()从类复制的说明:AbstractResourceThis implementation always returnsfalse.- 指定者:
isFile在接口中Resource- 覆盖:
isFile在类中AbstractFileResolvingResource- 另请参阅:
-
getName
This implementation returns the URL-decoded name of the file that this URL refers to.- 指定者:
getName在接口中Resource- 覆盖:
getName在类中AbstractResource- 另请参阅:
-
equals
This implementation compares the underlying URL references.- 覆盖:
equals在类中AbstractResource
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying URL reference.- 覆盖:
hashCode在类中AbstractResource
-
createRelative
This implementation creates aUrlBasedResource, 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
- 抛出:
IOException- if the relative resource cannot be determined- 另请参阅:
-
createRelativeURL
This 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. -
toString
从接口复制的说明:ResourceReturn a description for this resource, to be used for error output when working with the resource.Implementations are also encouraged to return this value from their
toStringmethod.- 指定者:
toString在接口中Resource- 覆盖:
toString在类中AbstractResource- 另请参阅:
-
from
Create a newUrlResourcefrom the givenURI.This factory method is a convenience for
UrlResource(URI)that catches anyMalformedURLExceptionand rethrows it wrapped in anUncheckedIOException; suitable for use inStreamandOptionalAPIs or other scenarios when a checkedIOExceptionis undesirable.- 参数:
uri- a URI- 抛出:
UncheckedIOException- if the given URL path is not valid- 从以下版本开始:
- 4.0
- 另请参阅:
-
from
Create a newUrlResourcefrom the given URL path.This factory method is a convenience for
UrlResource(String)that catches anyMalformedURLExceptionand rethrows it wrapped in anUncheckedIOException; suitable for use inStreamandOptionalAPIs or other scenarios when a checkedIOExceptionis undesirable.- 参数:
path- a URL path- 抛出:
UncheckedIOException- if the given URL path is not valid- 从以下版本开始:
- 4.0
- 另请参阅:
-