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

📄 arcreader.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="572" href="#572">572</a>     <em>/**<em>*</em></em><a name="573" href="#573">573</a> <em>     * Command-line interface to ARCReader.</em><a name="574" href="#574">574</a> <em>     *</em><a name="575" href="#575">575</a> <em>     * Here is the command-line interface:</em><a name="576" href="#576">576</a> <em>     * &lt;pre></em><a name="577" href="#577">577</a> <em>     * usage: java org.archive.io.arc.ARCReader [--offset=#] ARCFILE</em><a name="578" href="#578">578</a> <em>     *  -h,--help      Prints this message and exits.</em><a name="579" href="#579">579</a> <em>     *  -o,--offset    Outputs record at this offset into arc file.&lt;/pre></em><a name="580" href="#580">580</a> <em>     *</em><a name="581" href="#581">581</a> <em>     * &lt;p>See in &lt;code>$HERITRIX_HOME/bin/arcreader&lt;/code> for a script that'll</em><a name="582" href="#582">582</a> <em>     * take care of classpaths and the calling of ARCReader.</em><a name="583" href="#583">583</a> <em>     *</em><a name="584" href="#584">584</a> <em>     * &lt;p>Outputs using a pseudo-CDX format as described here:</em><a name="585" href="#585">585</a> <em>     * &lt;a href="<a href="http://www.archive.org/web/researcher/cdx_legend.php" target="alexandria_uri">http://www.archive.org/web/researcher/cdx_legend.php</a>">CDX</em><a name="586" href="#586">586</a> <em>     * Legent&lt;/a> and here</em><a name="587" href="#587">587</a> <em>     * &lt;a href="<a href="http://www.archive.org/web/researcher/example_cdx.php" target="alexandria_uri">http://www.archive.org/web/researcher/example_cdx.php</a>">Example&lt;/a>.</em><a name="588" href="#588">588</a> <em>     * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'.</em><a name="589" href="#589">589</a> <em>     * Hash is hard-coded straight SHA-1 hash of content.</em><a name="590" href="#590">590</a> <em>     *</em><a name="591" href="#591">591</a> <em>     * @param args Command-line arguments.</em><a name="592" href="#592">592</a> <em>     * @throws ParseException Failed parse of the command line.</em><a name="593" href="#593">593</a> <em>     * @throws IOException</em><a name="594" href="#594">594</a> <em>     * @throws java.text.ParseException</em><a name="595" href="#595">595</a> <em>     */</em><a name="596" href="#596">596</a>     <strong>public</strong> <strong>static</strong> <strong>void</strong> main(String [] args)<a name="597" href="#597">597</a>     throws ParseException, IOException, java.text.ParseException {<a name="598" href="#598">598</a>         Options options = <strong>new</strong> Options();<a name="599" href="#599">599</a>         options.addOption(<strong>new</strong> Option(<span class="string">"h"</span>,<span class="string">"help"</span>, false,<a name="600" href="#600">600</a>             <span class="string">"Prints this message and exits."</span>));<a name="601" href="#601">601</a>         options.addOption(<strong>new</strong> Option(<span class="string">"o"</span>,<span class="string">"offset"</span>, <strong>true</strong>,<a name="602" href="#602">602</a>             <span class="string">"Outputs record at this offset into arc file."</span>));<a name="603" href="#603">603</a>         options.addOption(<strong>new</strong> Option(<span class="string">"d"</span>,<span class="string">"digest"</span>, <strong>true</strong>,<a name="604" href="#604">604</a>             <span class="string">"Pass true|false. Expensive. Default: true (SHA-1)."</span>));<a name="605" href="#605">605</a>         options.addOption(<strong>new</strong> Option(<span class="string">"s"</span>,<span class="string">"strict"</span>, false,<a name="606" href="#606">606</a>             <span class="string">"Strict mode. Fails parse if incorrectly formatted ARC."</span>));<a name="607" href="#607">607</a>         options.addOption(<strong>new</strong> Option(<span class="string">"p"</span>,<span class="string">"parse"</span>, <strong>true</strong>,<a name="608" href="#608">608</a>         	<span class="string">"Pass true|false to parse HTTP Headers. Default: false."</span>));<a name="609" href="#609">609</a>         options.addOption(<strong>new</strong> Option(<span class="string">"f"</span>,<span class="string">"format"</span>, <strong>true</strong>,<a name="610" href="#610">610</a>             <span class="string">"Output options: 'cdx', cdxfile', 'dump', 'gzipdump',"</span> +<a name="611" href="#611">611</a>             <span class="string">"'or 'nohead'. Default: 'cdx'."</span>));<a name="612" href="#612">612</a>         PosixParser parser = <strong>new</strong> PosixParser();<a name="613" href="#613">613</a>         CommandLine cmdline = parser.parse(options, args, false);<a name="614" href="#614">614</a>         List cmdlineArgs = cmdline.getArgList();<a name="615" href="#615">615</a>         Option [] cmdlineOptions = cmdline.getOptions();<a name="616" href="#616">616</a>         HelpFormatter formatter = <strong>new</strong> HelpFormatter();<a name="617" href="#617">617</a> <a name="618" href="#618">618</a>         <em class="comment">// If no args, print help.</em><a name="619" href="#619">619</a>         <strong>if</strong> (cmdlineArgs.size() &lt;= 0) {<a name="620" href="#620">620</a>             usage(formatter, options, 0);<a name="621" href="#621">621</a>         }<a name="622" href="#622">622</a> <a name="623" href="#623">623</a>         <em class="comment">// Now look at options passed.</em><a name="624" href="#624">624</a>         <strong>long</strong> offset = -1;<a name="625" href="#625">625</a>         <strong>boolean</strong> digest = false;<a name="626" href="#626">626</a>         <strong>boolean</strong> strict = false;<a name="627" href="#627">627</a>         <strong>boolean</strong> parse = false;<a name="628" href="#628">628</a>         String format = CDX;<a name="629" href="#629">629</a>         <strong>for</strong> (<strong>int</strong> i = 0; i &lt; cmdlineOptions.length; i++) {<a name="630" href="#630">630</a>             <strong>switch</strong>(cmdlineOptions[i].getId()) {<a name="631" href="#631">631</a>                 <strong>case</strong> 'h':<a name="632" href="#632">632</a>                     usage(formatter, options, 0);<a name="633" href="#633">633</a>                     <strong>break</strong>;<a name="634" href="#634">634</a> <a name="635" href="#635">635</a>                 <strong>case</strong> 'o':<a name="636" href="#636">636</a>                     offset =<a name="637" href="#637">637</a>                         Long.parseLong(cmdlineOptions[i].getValue());<a name="638" href="#638">638</a>                     <strong>break</strong>;<a name="639" href="#639">639</a>                     <a name="640" href="#640">640</a>                 <strong>case</strong> 's':<a name="641" href="#641">641</a>                     strict = <strong>true</strong>;<a name="642" href="#642">642</a>                     <strong>break</strong>;<a name="643" href="#643">643</a>                     <a name="644" href="#644">644</a>                 <strong>case</strong> 'p':<a name="645" href="#645">645</a>                 	parse = getTrueOrFalse(cmdlineOptions[i].getValue());<a name="646" href="#646">646</a>                     <strong>break</strong>;<a name="647" href="#647">647</a>                     <a name="648" href="#648">648</a>                 <strong>case</strong> 'd':<a name="649" href="#649">649</a>                 	digest = getTrueOrFalse(cmdlineOptions[i].getValue());<a name="650" href="#650">650</a>                     <strong>break</strong>;<a name="651" href="#651">651</a>                     <a name="652" href="#652">652</a>                 <strong>case</strong> 'f':<a name="653" href="#653">653</a>                     format = cmdlineOptions[i].getValue().toLowerCase();<a name="654" href="#654">654</a>                     <strong>boolean</strong> match = false;<a name="655" href="#655">655</a>                     <em class="comment">// List of supported formats.</em><a name="656" href="#656">656</a>                     <strong>final</strong> String [] supportedFormats =<a name="657" href="#657">657</a>                 		{CDX, DUMP, GZIP_DUMP, NOHEAD, CDX_FILE};<a name="658" href="#658">658</a>                     <strong>for</strong> (<strong>int</strong> ii = 0; ii &lt; supportedFormats.length; ii++) {<a name="659" href="#659">659</a>                         <strong>if</strong> (supportedFormats[ii].equals(format)) {<a name="660" href="#660">660</a>                             match = <strong>true</strong>;<a name="661" href="#661">661</a>                             <strong>break</strong>;<a name="662" href="#662">662</a>                         }<a name="663" href="#663">663</a>                     }<a name="664" href="#664">664</a>                     <strong>if</strong> (!match) {<a name="665" href="#665">665</a>                         usage(formatter, options, 1);<a name="666" href="#666">666</a>                     }<a name="667" href="#667">667</a>                     <strong>break</strong>;<a name="668" href="#668">668</a> <a name="669" href="#669">669</a>                 <strong>default</strong>:<a name="670" href="#670">670</a>                     <strong>throw</strong> <strong>new</strong> RuntimeException(<span class="string">"Unexpected option: "</span> +<a name="671" href="#671">671</a>                         + cmdlineOptions[i].getId());<a name="672" href="#672">672</a>             }<a name="673" href="#673">673</a>         }<a name="674" href="#674">674</a>         <a name="675" href="#675">675</a>         <strong>if</strong> (offset >= 0) {<a name="676" href="#676">676</a>             <strong>if</strong> (cmdlineArgs.size() != 1) {<a name="677" href="#677">677</a>                 System.out.println(<span class="string">"Error: Pass one arcfile only."</span>);<a name="678" href="#678">678</a>                 usage(formatter, options, 1);<a name="679" href="#679">679</a>             }<a name="680" href="#680">680</a>             <a href="../../../../org/archive/io/arc/ARCReader.html">ARCReader</a> arc = ARCReaderFactory.get(<a name="681" href="#681">681</a>             	<strong>new</strong> File((String)cmdlineArgs.get(0)), offset);<a name="682" href="#682">682</a>             arc.setStrict(strict);<a name="683" href="#683">683</a>             arc.setParseHttpHeaders(parse);<a name="684" href="#684">684</a>             outputRecord(arc, format);<a name="685" href="#685">685</a>         } <strong>else</strong> {<a name="686" href="#686">686</a>             <strong>for</strong> (Iterator i = cmdlineArgs.iterator(); i.hasNext();) {<a name="687" href="#687">687</a>                 String urlOrPath = (String)i.next();<a name="688" href="#688">688</a>                 <strong>try</strong> {<a name="689" href="#689">689</a>                 	ARCReader r = ARCReaderFactory.get(urlOrPath);<a name="690" href="#690">690</a>                 	r.setStrict(strict);<a name="691" href="#691">691</a>                 	r.setParseHttpHeaders(parse);<a name="692" href="#692">692</a>                 	r.setDigest(digest);<a name="693" href="#693">693</a>                     output(r, format);<a name="694" href="#694">694</a>                 } <strong>catch</strong> (RuntimeException e) {<a name="695" href="#695">695</a>                     <em class="comment">// Write out name of file we failed on to help with</em><a name="696" href="#696">696</a>                     <em class="comment">// debugging.  Then print stack trace and try to keep</em><a name="697" href="#697">697</a>                     <em class="comment">// going.  We do this for case where we're being fed</em><a name="698" href="#698">698</a>                     <em class="comment">// a bunch of ARCs; just note the bad one and move</em><a name="699" href="#699">699</a>                     <em class="comment">// on to the next.</em><a name="700" href="#700">700</a>                     System.err.println(<span class="string">"Exception processing "</span> + urlOrPath +<a name="701" href="#701">701</a>                         <span class="string">": "</span> + e.getMessage());<a name="702" href="#702">702</a>                     e.printStackTrace(System.err);<a name="703" href="#703">703</a>                     System.exit(1);<a name="704" href="#704">704</a>                 }<a name="705" href="#705">705</a>             }<a name="706" href="#706">706</a>         }<a name="707" href="#707">707</a>     }<a name="708" href="#708">708</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 + -