类 ExtendableProtocolURLStreamHandler
- java.lang.Object
-
- java.net.URLStreamHandler
-
- io.microsphere.net.ExtendableProtocolURLStreamHandler
-
public abstract class ExtendableProtocolURLStreamHandler extends java.net.URLStreamHandler
Extendable ProtocolURLStreamHandler
class supports the sub-protocols, like "{protocol}:{sub-protocols[0]}: ... :{sub-protocols[n]}://...",- {protocol} : The protocol of
URLStreamHandler
is recognized byURL
(required) - {sub-protocols} : the list of sub-protocols that is
resolved
fromURL
(optional)
The method
initSubProtocolURLConnectionFactories(List)
that is overridden allows the sub-protocols to be extended, the prerequisite is the methodbeing invoked later.
If no {@link SubProtocolURLConnectionFactory} initialized or {@link URLConnection} open, the {@link #openFallbackConnection(URL, Proxy) fallback strategy} will be applied.
If there is no requirement to support the sub-protocol, the subclass only needs to override {@link #openConnection(URL, Proxy)} method.
If an instance is instantiated by the default constructor, the implementation class must the obey conventions as follow:
- The class must be the top level
- The simple class name must be "Handler"
- The class must not be present in the "default" or builtin package({@linkURLUtils #DEFAULT_HANDLER_PACKAGE_PREFIX "sun.net.www.protocol"})
A new instance also can specify some protocol via {@link #ExtendableProtocolURLStreamHandler(String) the constructor with the protocol argument}.
Node: these methods are overridden making final:
- {@link #openConnection(URL)}
- {@link #parseURL(URL, String, int, int)}
- {@link #equals(URL, URL)}
- {@link #hostsEqual(URL, URL)}
- {@link #hashCode(URL)}
- {@link #toExternalForm(URL)}
- 从以下版本开始:
- 1.0.0
- 作者:
- Mercy
- 另请参阅:
SubProtocolURLConnectionFactory
,URLStreamHandler
- {protocol} : The protocol of
-
-
构造器概要
构造器 构造器 说明 ExtendableProtocolURLStreamHandler()
The default constructor must obey the following conventions: The class must be the top level The simple class name must be "Handler" The class must not be present in the "default" or builtin package("sun.net.www.protocol"
)ExtendableProtocolURLStreamHandler(java.lang.String protocol)
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 protected boolean
equals(java.net.URL u1, java.net.URL u2)
static java.util.Set<java.lang.String>
getHandlePackages()
static java.lang.String
getHandlePackagesPropertyValue()
Get theSystem
property value of the packages ofURLStreamHandlers
.java.lang.String
getProtocol()
protected int
hashCode(java.net.URL u)
protected boolean
hostsEqual(java.net.URL u1, java.net.URL u2)
void
init()
protected void
initSubProtocolURLConnectionFactories(java.util.List<SubProtocolURLConnectionFactory> factories)
InitializeSubProtocolURLConnectionFactories
protected java.net.URLConnection
openConnection(java.net.URL u)
protected java.net.URLConnection
openConnection(java.net.URL u, java.net.Proxy p)
protected java.net.URLConnection
openFallbackConnection(java.net.URL url, java.net.Proxy proxy)
The subclass can override this method to open the fallbackURLConnection
if anySubProtocolURLConnectionFactory
does not create theURLConnection
.protected void
parseURL(java.net.URL u, java.lang.String spec, int start, int limit)
protected java.lang.String
reformSpec(java.net.URL url, java.lang.String spec, int start, int end, int limit)
Reform the string of specifiedURL
if its' scheme presents the sub-protocol, e,g.protected java.lang.String
resolveAuthority(java.net.URL url)
protected java.lang.String
resolvePath(java.net.URL url)
protected java.util.List<java.lang.String>
resolveSubProtocols(java.net.URL url)
Get the sub-protocols from the specifiedURL
protected java.lang.String
toExternalForm(java.net.URL u)
Reuses the algorithm ofURLStreamHandler.toExternalForm(URL)
using theStringBuilder
to theStringBuilder
.java.lang.String
toString()
-
-
-
构造器详细资料
-
ExtendableProtocolURLStreamHandler
public ExtendableProtocolURLStreamHandler()
The default constructor must obey the following conventions:- The class must be the top level
- The simple class name must be "Handler"
- The class must not be present in the "default" or builtin package(
"sun.net.www.protocol"
)
-
ExtendableProtocolURLStreamHandler
public ExtendableProtocolURLStreamHandler(java.lang.String protocol)
-
-
方法详细资料
-
getHandlePackages
public static java.util.Set<java.lang.String> getHandlePackages()
-
getHandlePackagesPropertyValue
public static java.lang.String getHandlePackagesPropertyValue()
Get theSystem
property value of the packages ofURLStreamHandlers
.- 返回:
null
if absent
-
init
public void init()
-
initSubProtocolURLConnectionFactories
protected void initSubProtocolURLConnectionFactories(java.util.List<SubProtocolURLConnectionFactory> factories)
InitializeSubProtocolURLConnectionFactories
- 参数:
factories
- the collection ofSubProtocolURLConnectionFactories
-
openConnection
protected final java.net.URLConnection openConnection(java.net.URL u) throws java.io.IOException
- 指定者:
openConnection
在类中java.net.URLStreamHandler
- 抛出:
java.io.IOException
-
openConnection
protected java.net.URLConnection openConnection(java.net.URL u, java.net.Proxy p) throws java.io.IOException
- 覆盖:
openConnection
在类中java.net.URLStreamHandler
- 抛出:
java.io.IOException
-
openFallbackConnection
protected java.net.URLConnection openFallbackConnection(java.net.URL url, java.net.Proxy proxy) throws java.io.IOException
The subclass can override this method to open the fallbackURLConnection
if anySubProtocolURLConnectionFactory
does not create theURLConnection
.- 参数:
url
- the URL that this connects toproxy
-Proxy
the proxy through which the connection will be made. If direct connection is desired, Proxy.NO_PROXY should be specified.- 返回:
null
as default- 抛出:
java.io.IOException
-
equals
protected final boolean equals(java.net.URL u1, java.net.URL u2)
- 覆盖:
equals
在类中java.net.URLStreamHandler
-
hashCode
protected final int hashCode(java.net.URL u)
- 覆盖:
hashCode
在类中java.net.URLStreamHandler
-
hostsEqual
protected final boolean hostsEqual(java.net.URL u1, java.net.URL u2)
- 覆盖:
hostsEqual
在类中java.net.URLStreamHandler
-
toExternalForm
protected final java.lang.String toExternalForm(java.net.URL u)
Reuses the algorithm ofURLStreamHandler.toExternalForm(URL)
using theStringBuilder
to theStringBuilder
.- 覆盖:
toExternalForm
在类中java.net.URLStreamHandler
- 参数:
u
- the URL.- 返回:
- a string representation of the URL argument.
-
parseURL
protected final void parseURL(java.net.URL u, java.lang.String spec, int start, int limit)
- 覆盖:
parseURL
在类中java.net.URLStreamHandler
-
reformSpec
protected java.lang.String reformSpec(java.net.URL url, java.lang.String spec, int start, int end, int limit)
Reform the string of specifiedURL
if its' scheme presents the sub-protocol, e,g. A string representing the URL is "jdbc:mysql://localhost:3307/mydb?charset=UTF-8#top", its'- scheme : "jdbc:mysql"
- host : "localhost"
- port : 3307
- path : "/mydb"
- query : "charset=UTF-8"
- ref : "top"
This scheme contains two parts, the former is "jdbc" as the protocol, the later is "mysql" called sub-protocol which is convenient to extend the fine-grain
URLStreamHandler
. In this case, the reformed string of specifiedURL
will be "jdbc://localhost:3307/mydb;_sp=mysql?charset=UTF-8#top".- 参数:
url
- theURL
to receive the result of parsing the spec.spec
- theString
representing the URL that must be parsed.start
- the character index at which to begin parsing. This is just past the ':
' (if there is one) that specifies the determination of the protocol name.end
- the index of the string "://" present in the URL from thestart
index, its' value is greater or equal 0.limit
- the character position to stop parsing at. This is the end of the string or the position of the "#
" character, if present. All information after the sharp sign indicates an anchor.- 返回:
- reformed the string of specified
URL
if the suffix o
-
resolveSubProtocols
protected java.util.List<java.lang.String> resolveSubProtocols(java.net.URL url)
Get the sub-protocols from the specifiedURL
- 参数:
url
-URL
- 返回:
- non-null
-
resolveAuthority
protected java.lang.String resolveAuthority(java.net.URL url)
-
resolvePath
protected java.lang.String resolvePath(java.net.URL url)
-
getProtocol
public final java.lang.String getProtocol()
-
toString
public java.lang.String toString()
- 覆盖:
toString
在类中java.lang.Object
-
-