⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uuri.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="149" href="#149">149</a> <em>     * @param escaped If escaped.</em><a name="150" href="#150">150</a> <em>     * @throws NullPointerException</em><a name="151" href="#151">151</a> <em>     * @throws URIException</em><a name="152" href="#152">152</a> <em>     */</em><a name="153" href="#153">153</a>     <strong>public</strong> <a href="../../../org/archive/net/UURI.html">UURI</a>(String uri, <strong>boolean</strong> escaped) throws URIException, NullPointerException {<a name="154" href="#154">154</a>         <strong>super</strong>(uri,escaped);<a name="155" href="#155">155</a>         normalize();<a name="156" href="#156">156</a>     }<a name="157" href="#157">157</a> <a name="158" href="#158">158</a>     <em>/**<em>*</em></em><a name="159" href="#159">159</a> <em>     * @param uri URI as string that is resolved relative to this UURI.</em><a name="160" href="#160">160</a> <em>     * @return UURI that uses this UURI as base.</em><a name="161" href="#161">161</a> <em>     * @throws URIException</em><a name="162" href="#162">162</a> <em>     */</em><a name="163" href="#163">163</a>     <strong>public</strong> <a href="../../../org/archive/net/UURI.html">UURI</a> resolve(String uri)<a name="164" href="#164">164</a>     throws URIException {<a name="165" href="#165">165</a>         <strong>return</strong> resolve(uri, false, <em class="comment">// assume not escaped</em><a name="166" href="#166">166</a>             <strong>this</strong>.getProtocolCharset());<a name="167" href="#167">167</a>     }<a name="168" href="#168">168</a> <a name="169" href="#169">169</a>     <em>/**<em>*</em></em><a name="170" href="#170">170</a> <em>     * @param uri URI as string that is resolved relative to this UURI.</em><a name="171" href="#171">171</a> <em>     * @param e True if escaped.</em><a name="172" href="#172">172</a> <em>     * @return UURI that uses this UURI as base.</em><a name="173" href="#173">173</a> <em>     * @throws URIException</em><a name="174" href="#174">174</a> <em>     */</em><a name="175" href="#175">175</a>     <strong>public</strong> <a href="../../../org/archive/net/UURI.html">UURI</a> resolve(String uri, <strong>boolean</strong> e)<a name="176" href="#176">176</a>     throws URIException {<a name="177" href="#177">177</a>         <strong>return</strong> resolve(uri, e, <strong>this</strong>.getProtocolCharset());<a name="178" href="#178">178</a>     }<a name="179" href="#179">179</a>     <a name="180" href="#180">180</a>     <em>/**<em>*</em></em><a name="181" href="#181">181</a> <em>     * @param uri URI as string that is resolved relative to this UURI.</em><a name="182" href="#182">182</a> <em>     * @param e True if uri is escaped.</em><a name="183" href="#183">183</a> <em>     * @param charset Charset to use.</em><a name="184" href="#184">184</a> <em>     * @return UURI that uses this UURI as base.</em><a name="185" href="#185">185</a> <em>     * @throws URIException</em><a name="186" href="#186">186</a> <em>     */</em><a name="187" href="#187">187</a>     <strong>public</strong> <a href="../../../org/archive/net/UURI.html">UURI</a> resolve(String uri, <strong>boolean</strong> e, String charset)<a name="188" href="#188">188</a>     throws URIException {<a name="189" href="#189">189</a>         <strong>return</strong> <strong>new</strong> <a href="../../../org/archive/net/UURI.html">UURI</a>(<strong>this</strong>, <strong>new</strong> <a href="../../../org/archive/net/UURI.html">UURI</a>(uri, e, charset));<a name="190" href="#190">190</a>     }<a name="191" href="#191">191</a> <a name="192" href="#192">192</a>     <em>/**<em>*</em></em><a name="193" href="#193">193</a> <em>     * Test an object if this UURI is equal to another.</em><a name="194" href="#194">194</a> <em>     *</em><a name="195" href="#195">195</a> <em>     * @param obj an object to compare</em><a name="196" href="#196">196</a> <em>     * @return true if two URI objects are equal</em><a name="197" href="#197">197</a> <em>     */</em><a name="198" href="#198">198</a>     <strong>public</strong> <strong>boolean</strong> equals(Object obj) {<a name="199" href="#199">199</a> <a name="200" href="#200">200</a>         <em class="comment">// normalize and test each components</em><a name="201" href="#201">201</a>         <strong>if</strong> (obj == <strong>this</strong>) {<a name="202" href="#202">202</a>             <strong>return</strong> <strong>true</strong>;<a name="203" href="#203">203</a>         }<a name="204" href="#204">204</a>         <strong>if</strong> (!(obj instanceof UURI)) {<a name="205" href="#205">205</a>             <strong>return</strong> false;<a name="206" href="#206">206</a>         }<a name="207" href="#207">207</a>         <a href="../../../org/archive/net/UURI.html">UURI</a> another = (UURI) obj;<a name="208" href="#208">208</a>         <em class="comment">// scheme</em><a name="209" href="#209">209</a>         <strong>if</strong> (!equals(<strong>this</strong>._scheme, another._scheme)) {<a name="210" href="#210">210</a>             <strong>return</strong> false;<a name="211" href="#211">211</a>         }<a name="212" href="#212">212</a>         <em class="comment">// is_opaque_part or is_hier_part?  and opaque</em><a name="213" href="#213">213</a>         <strong>if</strong> (!equals(<strong>this</strong>._opaque, another._opaque)) {<a name="214" href="#214">214</a>             <strong>return</strong> false;<a name="215" href="#215">215</a>         }<a name="216" href="#216">216</a>         <em class="comment">// is_hier_part</em><a name="217" href="#217">217</a>         <em class="comment">// has_authority</em><a name="218" href="#218">218</a>         <strong>if</strong> (!equals(<strong>this</strong>._authority, another._authority)) {<a name="219" href="#219">219</a>             <strong>return</strong> false;<a name="220" href="#220">220</a>         }<a name="221" href="#221">221</a>         <em class="comment">// path</em><a name="222" href="#222">222</a>         <strong>if</strong> (!equals(<strong>this</strong>._path, another._path)) {<a name="223" href="#223">223</a>             <strong>return</strong> false;<a name="224" href="#224">224</a>         }<a name="225" href="#225">225</a>         <em class="comment">// has_query</em><a name="226" href="#226">226</a>         <strong>if</strong> (!equals(<strong>this</strong>._query, another._query)) {<a name="227" href="#227">227</a>             <strong>return</strong> false;<a name="228" href="#228">228</a>         }<a name="229" href="#229">229</a>         <em class="comment">// UURIs do not have fragments</em><a name="230" href="#230">230</a>         <strong>return</strong> <strong>true</strong>;<a name="231" href="#231">231</a>     }<a name="232" href="#232">232</a> <a name="233" href="#233">233</a>     <em>/**<em>*</em></em><a name="234" href="#234">234</a> <em>     * Strips www variants from the host.</em><a name="235" href="#235">235</a> <em>     *</em><a name="236" href="#236">236</a> <em>     * Strips www[0-9]*\. from the host.  If calling getHostBaseName becomes a</em><a name="237" href="#237">237</a> <em>     * performance issue we should consider adding the hostBasename member that</em><a name="238" href="#238">238</a> <em>     * is set on initialization.</em><a name="239" href="#239">239</a> <em>     *</em><a name="240" href="#240">240</a> <em>     * @return Host's basename.</em><a name="241" href="#241">241</a> <em>     * @throws URIException</em><a name="242" href="#242">242</a> <em>     */</em><a name="243" href="#243">243</a>     <strong>public</strong> String getHostBasename() throws URIException {<a name="244" href="#244">244</a>         <em class="comment">// caching eliminated because this is rarely used</em><a name="245" href="#245">245</a>         <em class="comment">// (only benefits legacy DomainScope, which should</em><a name="246" href="#246">246</a>         <em class="comment">// be retired). Saves 4-byte object pointer in UURI</em><a name="247" href="#247">247</a>         <em class="comment">// instances.</em><a name="248" href="#248">248</a>         <strong>return</strong> (<strong>this</strong>.getReferencedHost() == <strong>null</strong>) <a name="249" href="#249">249</a>             ? <strong>null</strong> <a name="250" href="#250">250</a>             : TextUtils.replaceFirst(MASSAGEHOST_PATTERN, <a name="251" href="#251">251</a>                     <strong>this</strong>.getReferencedHost(), UURIFactory.EMPTY_STRING);<a name="252" href="#252">252</a>     }<a name="253" href="#253">253</a> <a name="254" href="#254">254</a>     <em>/**<em>*</em></em><a name="255" href="#255">255</a> <em>     * Override to cache result</em><a name="256" href="#256">256</a> <em>     * </em><a name="257" href="#257">257</a> <em>     * @return String representation of this URI</em><a name="258" href="#258">258</a> <em>     */</em><a name="259" href="#259">259</a>     <strong>public</strong> <strong>synchronized</strong> String toString() {<a name="260" href="#260">260</a>         <strong>if</strong> (<strong>this</strong>.cachedString == <strong>null</strong>) {<a name="261" href="#261">261</a>             <strong>this</strong>.cachedString = <strong>super</strong>.toString();<a name="262" href="#262">262</a>             coalesceUriStrings();<a name="263" href="#263">263</a>         }<a name="264" href="#264">264</a>         <strong>return</strong> <strong>this</strong>.cachedString;<a name="265" href="#265">265</a>     }<a name="266" href="#266">266</a> <a name="267" href="#267">267</a>     <strong>public</strong> <strong>synchronized</strong> String getEscapedURI() {<a name="268" href="#268">268</a>         <strong>if</strong> (<strong>this</strong>.cachedEscapedURI == <strong>null</strong>) {<a name="269" href="#269">269</a>             <strong>this</strong>.cachedEscapedURI = <strong>super</strong>.getEscapedURI();<a name="270" href="#270">270</a>             coalesceUriStrings();<a name="271" href="#271">271</a>         }<a name="272" href="#272">272</a>         <strong>return</strong> <strong>this</strong>.cachedEscapedURI;<a name="273" href="#273">273</a>     }<a name="274" href="#274">274</a> <a name="275" href="#275">275</a>     <em>/**<em>*</em></em><a name="276" href="#276">276</a> <em>     * The two String fields cachedString and cachedEscapedURI are </em><a name="277" href="#277">277</a> <em>     * usually identical; if so, coalesce into a single instance. </em><a name="278" href="#278">278</a> <em>     */</em><a name="279" href="#279">279</a>     <strong>protected</strong> <strong>void</strong> coalesceUriStrings() {<a name="280" href="#280">280</a>         <strong>if</strong> (<strong>this</strong>.cachedString != <strong>null</strong> &amp;&amp; <strong>this</strong>.cachedEscapedURI != <strong>null</strong><a name="281" href="#281">281</a>                 &amp;&amp; <strong>this</strong>.cachedString.length() == <strong>this</strong>.cachedEscapedURI.length()) {<a name="282" href="#282">282</a>             <em class="comment">// lengths will only be identical if contents are identical</em><a name="283" href="#283">283</a>             <em class="comment">// (deescaping will always shrink length), so coalesce to</em><a name="284" href="#284">284</a>             <em class="comment">// use only single cached instance</em><a name="285" href="#285">285</a>             <strong>this</strong>.cachedString = <strong>this</strong>.cachedEscapedURI;<a name="286" href="#286">286</a>         }<a name="287" href="#287">287</a>     }<a name="288" href="#288">288</a>     <a name="289" href="#289">289</a>     <strong>public</strong> <strong>synchronized</strong> String getHost() throws URIException {<a name="290" href="#290">290</a>         <strong>if</strong> (<strong>this</strong>.cachedHost == <strong>null</strong>) {<a name="291" href="#291">291</a>             <em class="comment">// If this._host is null, 3.0 httpclient throws</em><a name="292" href="#292">292</a>             <em class="comment">// illegalargumentexception.  Don't go there.</em><a name="293" href="#293">293</a>             <strong>if</strong> (<strong>this</strong>._host != <strong>null</strong>) {<a name="294" href="#294">294</a>             	<strong>this</strong>.cachedHost = <strong>super</strong>.getHost();<a name="295" href="#295">295</a>                 coalesceHostAuthorityStrings();<a name="296" href="#296">296</a>             }<a name="297" href="#297">297</a>         }<a name="298" href="#298">298</a>         <strong>return</strong> <strong>this</strong>.cachedHost;<a name="299" href="#299">299</a>     }<a name="300" href="#300">300</a>     <a name="301" href="#301">301</a>     <em>/**<em>*</em></em><a name="302" href="#302">302</a> <em>     * The two String fields cachedHost and cachedAuthorityMinusUserInfo are </em><a name="303" href="#303">303</a> <em>     * usually identical; if so, coalesce into a single instance. </em><a name="304" href="#304">304</a> <em>     */</em><a name="305" href="#305">305</a>     <strong>protected</strong> <strong>void</strong> coalesceHostAuthorityStrings() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -