📄 fetchftp.html
字号:
<a name="481" href="#481">481</a> <em>/**<em>*</em></em><a name="482" href="#482">482</a> <em> * Returns the <code>extract.parent</code> attribute for this</em><a name="483" href="#483">483</a> <em> * <code>FetchFTP</code> and the given curi.</em><a name="484" href="#484">484</a> <em> * </em><a name="485" href="#485">485</a> <em> * @param curi the curi whose attribute to return</em><a name="486" href="#486">486</a> <em> * @return that curi's <code>extract-parent</code></em><a name="487" href="#487">487</a> <em> */</em><a name="488" href="#488">488</a> <strong>public</strong> <strong>boolean</strong> getExtractParent(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="489" href="#489">489</a> <strong>return</strong> (Boolean)get(curi, ATTR_EXTRACT_PARENT, DEFAULT_EXTRACT_PARENT);<a name="490" href="#490">490</a> }<a name="491" href="#491">491</a> <a name="492" href="#492">492</a> <a name="493" href="#493">493</a> <em>/**<em>*</em></em><a name="494" href="#494">494</a> <em> * Returns the <code>timeout-seconds</code> attribute for this</em><a name="495" href="#495">495</a> <em> * <code>FetchFTP</code> and the given curi.</em><a name="496" href="#496">496</a> <em> * </em><a name="497" href="#497">497</a> <em> * @param curi the curi whose attribute to return</em><a name="498" href="#498">498</a> <em> * @return that curi's <code>timeout-seconds</code></em><a name="499" href="#499">499</a> <em> */</em><a name="500" href="#500">500</a> <strong>public</strong> <strong>int</strong> getTimeout(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="501" href="#501">501</a> <strong>return</strong> (Integer)get(curi, ATTR_TIMEOUT, DEFAULT_TIMEOUT);<a name="502" href="#502">502</a> }<a name="503" href="#503">503</a> <a name="504" href="#504">504</a> <a name="505" href="#505">505</a> <em>/**<em>*</em></em><a name="506" href="#506">506</a> <em> * Returns the <code>max-length-bytes</code> attribute for this</em><a name="507" href="#507">507</a> <em> * <code>FetchFTP</code> and the given curi.</em><a name="508" href="#508">508</a> <em> * </em><a name="509" href="#509">509</a> <em> * @param curi the curi whose attribute to return</em><a name="510" href="#510">510</a> <em> * @return that curi's <code>max-length-bytes</code></em><a name="511" href="#511">511</a> <em> */</em><a name="512" href="#512">512</a> <strong>public</strong> <strong>long</strong> getMaxLength(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="513" href="#513">513</a> <strong>return</strong> (Long)get(curi, ATTR_MAX_LENGTH, DEFAULT_MAX_LENGTH);<a name="514" href="#514">514</a> }<a name="515" href="#515">515</a> <a name="516" href="#516">516</a> <a name="517" href="#517">517</a> <em>/**<em>*</em></em><a name="518" href="#518">518</a> <em> * Returns the <code>fetch-bandwidth</code> attribute for this</em><a name="519" href="#519">519</a> <em> * <code>FetchFTP</code> and the given curi.</em><a name="520" href="#520">520</a> <em> * </em><a name="521" href="#521">521</a> <em> * @param curi the curi whose attribute to return</em><a name="522" href="#522">522</a> <em> * @return that curi's <code>fetch-bandwidth</code></em><a name="523" href="#523">523</a> <em> */</em><a name="524" href="#524">524</a> <strong>public</strong> <strong>int</strong> getFetchBandwidth(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="525" href="#525">525</a> <strong>return</strong> (Integer)get(curi, ATTR_BANDWIDTH, DEFAULT_BANDWIDTH);<a name="526" href="#526">526</a> }<a name="527" href="#527">527</a> <a name="528" href="#528">528</a> <a name="529" href="#529">529</a> <em>/**<em>*</em></em><a name="530" href="#530">530</a> <em> * Returns the username and password for the given URI. This method</em><a name="531" href="#531">531</a> <em> * always returns an array of length 2. The first element in the returned</em><a name="532" href="#532">532</a> <em> * array is the username for the URI, and the second element is the</em><a name="533" href="#533">533</a> <em> * password.</em><a name="534" href="#534">534</a> <em> * </em><a name="535" href="#535">535</a> <em> * <p>If the URI itself contains the username and password (i.e., it looks</em><a name="536" href="#536">536</a> <em> * like <code>ftp://username:password@host/path</code>) then that username</em><a name="537" href="#537">537</a> <em> * and password are returned.</em><a name="538" href="#538">538</a> <em> * </em><a name="539" href="#539">539</a> <em> * <p>Otherwise the settings system is probed for the <code>username</code></em><a name="540" href="#540">540</a> <em> * and <code>password</code> attributes for this <code>FTPFetch</code></em><a name="541" href="#541">541</a> <em> * and the given <code>curi</code> context. The values of those </em><a name="542" href="#542">542</a> <em> * attributes are then returned.</em><a name="543" href="#543">543</a> <em> * </em><a name="544" href="#544">544</a> <em> * @param curi the curi whose username and password to return</em><a name="545" href="#545">545</a> <em> * @return an array containing the username and password</em><a name="546" href="#546">546</a> <em> */</em><a name="547" href="#547">547</a> <strong>private</strong> String[] getAuth(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="548" href="#548">548</a> String[] result = <strong>new</strong> String[2];<a name="549" href="#549">549</a> <a href="../../../../org/archive/net/UURI.html">UURI</a> uuri = curi.getUURI();<a name="550" href="#550">550</a> String userinfo;<a name="551" href="#551">551</a> <strong>try</strong> {<a name="552" href="#552">552</a> userinfo = uuri.getUserinfo();<a name="553" href="#553">553</a> } <strong>catch</strong> (URIException e) {<a name="554" href="#554">554</a> assert false;<a name="555" href="#555">555</a> logger.finest(<span class="string">"getUserinfo raised URIException."</span>);<a name="556" href="#556">556</a> userinfo = <strong>null</strong>;<a name="557" href="#557">557</a> }<a name="558" href="#558">558</a> <strong>if</strong> (userinfo != <strong>null</strong>) {<a name="559" href="#559">559</a> <strong>int</strong> p = userinfo.indexOf(':');<a name="560" href="#560">560</a> <strong>if</strong> (p > 0) {<a name="561" href="#561">561</a> result[0] = userinfo.substring(0,p);<a name="562" href="#562">562</a> result[1] = userinfo.substring(p + 1);<a name="563" href="#563">563</a> <strong>return</strong> result;<a name="564" href="#564">564</a> }<a name="565" href="#565">565</a> }<a name="566" href="#566">566</a> result[0] = (String)get(curi, ATTR_USERNAME, DEFAULT_USERNAME);<a name="567" href="#567">567</a> result[1] = (String)get(curi, ATTR_PASSWORD, DEFAULT_PASSWORD);<a name="568" href="#568">568</a> <strong>return</strong> result;<a name="569" href="#569">569</a> }<a name="570" href="#570">570</a> <a name="571" href="#571">571</a> <a name="572" href="#572">572</a> <em>/**<em>*</em></em><a name="573" href="#573">573</a> <em> * Determines the password for the given URI. If the URI itself contains</em><a name="574" href="#574">574</a> <em> * a password, then that password is returned. Otherwise the settings</em><a name="575" href="#575">575</a> <em> * system is probed for the <code>password</code> attribute, and the value</em><a name="576" href="#576">576</a> <em> * for that attribute is returned.</em><a name="577" href="#577">577</a> <em> * </em><a name="578" href="#578">578</a> <em> * @param curi the curi whose password to return</em><a name="579" href="#579">579</a> <em> * @return that password</em><a name="580" href="#580">580</a> <em> */</em><a name="581" href="#581">581</a> <strong>public</strong> String determinePassword(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="582" href="#582">582</a> <strong>return</strong> (String)get(curi, ATTR_PASSWORD, DEFAULT_PASSWORD);<a name="583" href="#583">583</a> }<a name="584" href="#584">584</a> <a name="585" href="#585">585</a> <a name="586" href="#586">586</a> <em>/**<em>*</em></em><a name="587" href="#587">587</a> <em> * Quietly closes the given socket.</em><a name="588" href="#588">588</a> <em> * </em><a name="589" href="#589">589</a> <em> * @param socket the socket to close</em><a name="590" href="#590">590</a> <em> */</em><a name="591" href="#591">591</a> <strong>private</strong> <strong>static</strong> <strong>void</strong> close(Socket socket) {<a name="592" href="#592">592</a> <strong>try</strong> {<a name="593" href="#593">593</a> socket.close();<a name="594" href="#594">594</a> } <strong>catch</strong> (IOException e) {<a name="595" href="#595">595</a> logger.log(Level.WARNING, <span class="string">"IO error closing socket."</span>, e);<a name="596" href="#596">596</a> }<a name="597" href="#597">597</a> }<a name="598" href="#598">598</a> <a name="599" href="#599">599</a> <a name="600" href="#600">600</a> <em>/**<em>*</em></em><a name="601" href="#601">601</a> <em> * Quietly closes the given sequence.</em><a name="602" href="#602">602</a> <em> * If an IOException is raised, this method logs it as a warning.</em><a name="603" href="#603">603</a> <em> * </em><a name="604" href="#604">604</a> <em> * @param seq the sequence to close</em><a name="605" href="#605">605</a> <em> */</em><a name="606" href="#606">606</a> <strong>private</strong> <strong>static</strong> <strong>void</strong> close(<a href="../../../../org/archive/io/ReplayCharSequence.html">ReplayCharSequence</a> seq) {<a name="607" href="#607">607</a> <strong>if</strong> (seq == <strong>null</strong>) {<a name="608" href="#608">608</a> <strong>return</strong>;<a name="609" href="#609">609</a> }<a name="610" href="#610">610</a> <strong>try</strong> {<a name="611" href="#611">611</a> seq.close();<a name="612" href="#612">612</a> } <strong>catch</strong> (IOException e) {<a name="613" href="#613">613</a> logger.log(Level.WARNING, <span class="string">"IO error closing ReplayCharSequence."</span>, <a name="614" href="#614">614</a> e);<a name="615" href="#615">615</a> }<a name="616" href="#616">616</a> }<a name="617" href="#617">617</a> <a name="618" href="#618">618</a> <a name="619" href="#619">619</a> <em>/**<em>*</em></em><a name="620" href="#620">620</a> <em> * Quietly disconnects from the given FTP client.</em><a name="621" href="#621">621</a> <em> * If an IOException is raised, this method logs it as a warning.</em><a name="622" href="#622">622</a> <em> * </em><a name="623" href="#623">623</a> <em> * @param client the client to disconnect</em><a name="624" href="#624">624</a> <em> */</em><a name="625" href="#625">625</a> <strong>private</strong> <strong>static</strong> <strong>void</strong> disconnect(<a href="../../../../org/archive/net/ClientFTP.html">ClientFTP</a> client) {<a name="626" href="#626">626</a> <strong>if</strong> (client.isConnected()) <strong>try</strong> {<a name="627" href="#627">627</a> client.disconnect();<a name="628" href="#628">628</a> } <strong>catch</strong> (IOException e) {<a name="629" href="#629">629</a> <strong>if</strong> (logger.isLoggable(Level.WARNING)) {<a name="630" href="#630">630</a> logger.warning(<span class="string">"Could not disconnect from FTP client: "</span> <a name="631" href="#631">631</a> + e.getMessage());<a name="632" href="#632">632</a> }<a name="633" href="#633">633</a> } <a name="634" href="#634">634</a> }<a name="635" href="#635">635</a> <a name="636" href="#636">636</a> <a name="637" href="#637">637</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -