类 UrlResource
- 所有已实现的接口:
InputStreamSource,Resource,ThrowingConsumer<OutputStream>,Consumer<OutputStream>
- 直接已知子类:
FileUrlResource
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
- 作者:
- Harry Yang, Juergen Hoeller, Sam Brannen
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private static final Stringprivate StringCleaned URL String (with normalized path), used for comparisons.private final URIOriginal URI, if available; used for URI and File access.private final URLOriginal URL, used for actual access.从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器构造器说明UrlResource(String path) Create a newUrlResourcebased on a URI path.UrlResource(String protocol, String location) Create a newUrlResourcebased on a URI specification.UrlResource(String protocol, String location, String fragment) Create a newUrlResourcebased on a URI specification.UrlResource(URI uri) Create a newUrlResourcebased on the given URI object.UrlResource(URL url) Create a newUrlResourcebased on the given URL object. -
方法概要
修饰符和类型方法说明createRelative(String relativePath) This implementation creates aUrlResource, 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.protected voidCustomize the givenURLConnectionbefore fetching the resource.booleanThis implementation compares the underlying URL references.static UrlResourceCreate a newUrlResourcefrom the given URL path.static UrlResourceCreate a newUrlResourcefrom the givenURI.private StringLazily determine a cleaned URL for the given original URL.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()This implementation returns a description that includes the URL.从类继承的方法 cn.taketoday.core.io.AbstractFileResolvingResource
checkReadable, contentLength, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannel从类继承的方法 cn.taketoday.core.io.AbstractResource
isDirectory, isOpen, list, list从接口继承的方法 cn.taketoday.core.io.InputStreamSource
acceptWithException, getReader, getReader, transferTo从接口继承的方法 cn.taketoday.core.io.Resource
getContentAsByteArray, getContentAsString从接口继承的方法 cn.taketoday.util.function.ThrowingConsumer
accept, accept, throwing
-
字段详细资料
-
AUTHORIZATION
- 另请参阅:
-
uri
Original URI, if available; used for URI and File access. -
url
Original URL, used for actual access. -
cleanedUrl
Cleaned URL String (with normalized path), used for comparisons.
-
-
构造器详细资料
-
UrlResource
Create a newUrlResourcebased on the given URI object.- 参数:
uri- a URI- 抛出:
MalformedURLException- if the given URL path is not valid- 从以下版本开始:
- 4.0
-
UrlResource
Create a newUrlResourcebased on the given URL object.- 参数:
url- a URL
-
UrlResource
Create a newUrlResourcebased on a URI path.Note: The given path needs to be pre-encoded if necessary.
- 参数:
path- a URI path- 抛出:
MalformedURLException- if the given URI path is not valid- 从以下版本开始:
- 4.0
- 另请参阅:
-
UrlResource
Create 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"- 抛出:
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 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)- 抛出:
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.- 返回:
- the input stream for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource does not existIOException- if the content stream could not be opened- 另请参阅:
-
customizeConnection
从类复制的说明:AbstractFileResolvingResourceCustomize the givenURLConnectionbefore fetching the resource.Calls
ResourceUtils.useCachesIfNecessary(URLConnection)and delegates toAbstractFileResolvingResource.customizeConnection(HttpURLConnection)if possible. Can be overridden in subclasses.- 覆盖:
customizeConnection在类中AbstractFileResolvingResource- 参数:
con- the URLConnection to customize- 抛出:
IOException- if thrown from URLConnection methods
-
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- 另请参阅:
-
getCleanedUrl
Lazily determine a cleaned URL for the given original URL. -
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 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
- 抛出:
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
This implementation returns a description that includes the URL.- 指定者:
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
- 另请参阅:
-