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

📄 recoveryjournal.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="264" href="#264">264</a>         } <strong>catch</strong> (InterruptedException e) {<a name="265" href="#265">265</a>             <em class="comment">// TODO Auto-generated catch block</em><a name="266" href="#266">266</a>             e.printStackTrace();<a name="267" href="#267">267</a>         }<a name="268" href="#268">268</a>     }<a name="269" href="#269">269</a>     <a name="270" href="#270">270</a>     <em>/**<em>*</em></em><a name="271" href="#271">271</a> <em>     * Import just the SUCCESS (and possibly FAILURE) URIs from the given</em><a name="272" href="#272">272</a> <em>     * recovery log into the frontier as considered included. </em><a name="273" href="#273">273</a> <em>     * </em><a name="274" href="#274">274</a> <em>     * @param source recovery log file to use</em><a name="275" href="#275">275</a> <em>     * @param frontier frontier to update</em><a name="276" href="#276">276</a> <em>     * @param retainFailures whether failure ('Ff') URIs should count as done</em><a name="277" href="#277">277</a> <em>     * @return number of lines in recovery log (for reference)</em><a name="278" href="#278">278</a> <em>     * @throws IOException</em><a name="279" href="#279">279</a> <em>     */</em><a name="280" href="#280">280</a>     <strong>private</strong> <strong>static</strong> <strong>int</strong> importCompletionInfoFromLog(File source, <a name="281" href="#281">281</a>             <a href="../../../../org/archive/crawler/framework/Frontier.html">Frontier</a> frontier, <strong>boolean</strong> retainFailures) throws IOException {<a name="282" href="#282">282</a>         <em class="comment">// Scan log for all 'Fs' lines: add as 'alreadyIncluded'</em><a name="283" href="#283">283</a>         BufferedInputStream is = getBufferedInput(source);<a name="284" href="#284">284</a>         <em class="comment">// create MutableString of good starting size (will grow if necessary)</em><a name="285" href="#285">285</a>         MutableString read = <strong>new</strong> MutableString(UURI.MAX_URL_LENGTH); <a name="286" href="#286">286</a>         <strong>int</strong> lines = 0; <a name="287" href="#287">287</a>         <strong>try</strong> {<a name="288" href="#288">288</a>             <strong>while</strong> (readLine(is,read)) {<a name="289" href="#289">289</a>                 lines++;<a name="290" href="#290">290</a>                 <strong>boolean</strong> wasSuccess = read.startsWith(F_SUCCESS);<a name="291" href="#291">291</a>                 <strong>if</strong> (wasSuccess<a name="292" href="#292">292</a> 						|| (retainFailures &amp;&amp; read.startsWith(F_FAILURE))) {<a name="293" href="#293">293</a>                     <em class="comment">// retrieve first (only) URL on line </em><a name="294" href="#294">294</a>                     String s = read.subSequence(3,read.length()).toString();<a name="295" href="#295">295</a>                     <strong>try</strong> {<a name="296" href="#296">296</a>                         <a href="../../../../org/archive/net/UURI.html">UURI</a> u = UURIFactory.getInstance(s);<a name="297" href="#297">297</a>                         frontier.considerIncluded(u);<a name="298" href="#298">298</a>                         <strong>if</strong>(wasSuccess) {<a name="299" href="#299">299</a>                             <strong>if</strong> (frontier.getFrontierJournal() != <strong>null</strong>) {<a name="300" href="#300">300</a>                                 frontier.getFrontierJournal().<a name="301" href="#301">301</a>                                     finishedSuccess(u);<a name="302" href="#302">302</a>                             }<a name="303" href="#303">303</a>                         } <strong>else</strong> {<a name="304" href="#304">304</a>                             <em class="comment">// carryforward failure, in case future recovery</em><a name="305" href="#305">305</a>                             <em class="comment">// wants to no retain them as finished </em><a name="306" href="#306">306</a>                             <strong>if</strong> (frontier.getFrontierJournal() != <strong>null</strong>) {<a name="307" href="#307">307</a>                                 frontier.getFrontierJournal().<a name="308" href="#308">308</a>                                     finishedFailure(u);<a name="309" href="#309">309</a>                             }<a name="310" href="#310">310</a>                         }<a name="311" href="#311">311</a>                     } <strong>catch</strong> (URIException e) {<a name="312" href="#312">312</a>                         e.printStackTrace();<a name="313" href="#313">313</a>                     }<a name="314" href="#314">314</a>                 }<a name="315" href="#315">315</a>                 <strong>if</strong>((lines%PROGRESS_INTERVAL)==0) {<a name="316" href="#316">316</a>                     <em class="comment">// every 1 million lines, print progress</em><a name="317" href="#317">317</a>                     LOGGER.info(<a name="318" href="#318">318</a>                             <span class="string">"at line "</span> + lines <a name="319" href="#319">319</a>                             + <span class="string">" alreadyIncluded count = "</span> +<a name="320" href="#320">320</a>                             frontier.discoveredUriCount());<a name="321" href="#321">321</a>                 }<a name="322" href="#322">322</a>             }<a name="323" href="#323">323</a>         } <strong>catch</strong> (EOFException e) {<a name="324" href="#324">324</a>             <em class="comment">// expected in some uncleanly-closed recovery logs; ignore</em><a name="325" href="#325">325</a>         } <strong>finally</strong> {<a name="326" href="#326">326</a>             is.close();<a name="327" href="#327">327</a>         }<a name="328" href="#328">328</a>         <strong>return</strong> lines;<a name="329" href="#329">329</a>     }<a name="330" href="#330">330</a> <a name="331" href="#331">331</a>     <em>/**<em>*</em></em><a name="332" href="#332">332</a> <em>     * Read a line from the given bufferedinputstream into the MutableString.</em><a name="333" href="#333">333</a> <em>     * Return true if a line was read; false if EOF. </em><a name="334" href="#334">334</a> <em>     * </em><a name="335" href="#335">335</a> <em>     * @param is</em><a name="336" href="#336">336</a> <em>     * @param read</em><a name="337" href="#337">337</a> <em>     * @return True if we read a line.</em><a name="338" href="#338">338</a> <em>     * @throws IOException</em><a name="339" href="#339">339</a> <em>     */</em><a name="340" href="#340">340</a>     <strong>private</strong> <strong>static</strong> <strong>boolean</strong> readLine(BufferedInputStream is, MutableString read)<a name="341" href="#341">341</a>     throws IOException {<a name="342" href="#342">342</a>         read.length(0);<a name="343" href="#343">343</a>         <strong>int</strong> c = is.read();<a name="344" href="#344">344</a>         <strong>while</strong>((c!=-1)&amp;&amp;c!='\n'&amp;&amp;c!='\r') {<a name="345" href="#345">345</a>             read.append((<strong>char</strong>)c);<a name="346" href="#346">346</a>             c = is.read();<a name="347" href="#347">347</a>         }<a name="348" href="#348">348</a>         <strong>if</strong>(c==-1 &amp;&amp; read.length()==0) {<a name="349" href="#349">349</a>             <em class="comment">// EOF and none read; return false</em><a name="350" href="#350">350</a>             <strong>return</strong> false;<a name="351" href="#351">351</a>         }<a name="352" href="#352">352</a>         <strong>if</strong>(c=='\n') {<a name="353" href="#353">353</a>             <em class="comment">// consume LF following CR, if present</em><a name="354" href="#354">354</a>             is.mark(1);<a name="355" href="#355">355</a>             <strong>if</strong>(is.read()!='\r') {<a name="356" href="#356">356</a>                 is.reset();<a name="357" href="#357">357</a>             }<a name="358" href="#358">358</a>         }<a name="359" href="#359">359</a>         <em class="comment">// a line (possibly blank) was read</em><a name="360" href="#360">360</a>         <strong>return</strong> <strong>true</strong>;<a name="361" href="#361">361</a>     }<a name="362" href="#362">362</a> <a name="363" href="#363">363</a>     <em>/**<em>*</em></em><a name="364" href="#364">364</a> <em>     * Import all ADDs from given recovery log into the frontier's queues</em><a name="365" href="#365">365</a> <em>     * (excepting those the frontier drops as already having been included)</em><a name="366" href="#366">366</a> <em>     * </em><a name="367" href="#367">367</a> <em>     * @param source recovery log file to use</em><a name="368" href="#368">368</a> <em>     * @param frontier frontier to update</em><a name="369" href="#369">369</a> <em>     * @param lines total lines noted in recovery log earlier</em><a name="370" href="#370">370</a> <em>     * @param enough latch signalling 'enough' URIs queued to begin crawling</em><a name="371" href="#371">371</a> <em>     */</em><a name="372" href="#372">372</a>     <strong>private</strong> <strong>static</strong> <strong>void</strong> importQueuesFromLog(File source, <a href="../../../../org/archive/crawler/framework/Frontier.html">Frontier</a> frontier,<a name="373" href="#373">373</a>             <strong>int</strong> lines, CountDownLatch enough) {<a name="374" href="#374">374</a>         BufferedInputStream is;<a name="375" href="#375">375</a>         <em class="comment">// create MutableString of good starting size (will grow if necessary)</em><a name="376" href="#376">376</a>         MutableString read = <strong>new</strong> MutableString(UURI.MAX_URL_LENGTH);<a name="377" href="#377">377</a>         <strong>long</strong> queuedAtStart = frontier.queuedUriCount();<a name="378" href="#378">378</a>         <strong>long</strong> queuedDuringRecovery = 0;<a name="379" href="#379">379</a>         <strong>int</strong> qLines = 0;<a name="380" href="#380">380</a>         <a name="381" href="#381">381</a>         <strong>try</strong> {<a name="382" href="#382">382</a>             <em class="comment">// Scan log for all 'F+' lines: if not alreadyIncluded, schedule for</em><a name="383" href="#383">383</a>             <em class="comment">// visitation</em><a name="384" href="#384">384</a>             is = getBufferedInput(source);<a name="385" href="#385">385</a>             <strong>try</strong> {<a name="386" href="#386">386</a>                 <strong>while</strong> (readLine(is,read)) {<a name="387" href="#387">387</a>                     qLines++;<a name="388" href="#388">388</a>                     <strong>if</strong> (read.startsWith(F_ADD)) {<a name="389" href="#389">389</a>                         <a href="../../../../org/archive/net/UURI.html">UURI</a> u;<a name="390" href="#390">390</a>                         CharSequence args[] = splitOnSpaceRuns(read);<a name="391" href="#391">391</a>                         <strong>try</strong> {<a name="392" href="#392">392</a>                             u = UURIFactory.getInstance(args[1].toString());<a name="393" href="#393">393</a>                             String pathFromSeed = (args.length > 2)?<a name="394" href="#394">394</a>                                 args[2].toString() : <span class="string">""</span>;<a name="395" href="#395">395</a>                             <a href="../../../../org/archive/net/UURI.html">UURI</a> via = (args.length > 3)?<a name="396" href="#396">396</a>                                 UURIFactory.getInstance(args[3].toString()):<a name="397" href="#397">397</a>                                 <strong>null</strong>;<a name="398" href="#398">398</a>                             String viaContext = (args.length > 4)?<a name="399" href="#399">399</a>                                     args[4].toString(): <span class="string">""</span>;

⌨️ 快捷键说明

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