📄 arcreaderfactory.html
字号:
<a name="286" href="#286">286</a> <em> * Constructor.</em><a name="287" href="#287">287</a> <em> * </em><a name="288" href="#288">288</a> <em> * @param f Uncompressed arcfile to read.</em><a name="289" href="#289">289</a> <em> * @param offset Offset at which to position ARCReader.</em><a name="290" href="#290">290</a> <em> * @throws IOException</em><a name="291" href="#291">291</a> <em> */</em><a name="292" href="#292">292</a> <strong>public</strong> UncompressedARCReader(<strong>final</strong> File f, <strong>final</strong> <strong>long</strong> offset)<a name="293" href="#293">293</a> throws IOException {<a name="294" href="#294">294</a> <em class="comment">// Arc file has been tested for existence by time it has come</em><a name="295" href="#295">295</a> <em class="comment">// to here.</em><a name="296" href="#296">296</a> setIn(getInputStream(f, offset));<a name="297" href="#297">297</a> initialize(f.getAbsolutePath());<a name="298" href="#298">298</a> }<a name="299" href="#299">299</a> <a name="300" href="#300">300</a> <em>/**<em>*</em></em><a name="301" href="#301">301</a> <em> * Constructor.</em><a name="302" href="#302">302</a> <em> * </em><a name="303" href="#303">303</a> <em> * @param f Uncompressed arc to read.</em><a name="304" href="#304">304</a> <em> * @param is InputStream.</em><a name="305" href="#305">305</a> <em> */</em><a name="306" href="#306">306</a> <strong>public</strong> UncompressedARCReader(<strong>final</strong> String f, <strong>final</strong> InputStream is) {<a name="307" href="#307">307</a> <em class="comment">// Arc file has been tested for existence by time it has come</em><a name="308" href="#308">308</a> <em class="comment">// to here.</em><a name="309" href="#309">309</a> setIn(is);<a name="310" href="#310">310</a> initialize(f);<a name="311" href="#311">311</a> }<a name="312" href="#312">312</a> }<a name="313" href="#313">313</a> <a name="314" href="#314">314</a> <em>/**<em>*</em></em><a name="315" href="#315">315</a> <em> * Compressed arc file reader.</em><a name="316" href="#316">316</a> <em> * </em><a name="317" href="#317">317</a> <em> * @author stack</em><a name="318" href="#318">318</a> <em> */</em><a name="319" href="#319">319</a> <strong>private</strong> <strong>class</strong> CompressedARCReader <strong>extends</strong> <a href="../../../../org/archive/io/arc/ARCReader.html">ARCReader</a> {<a name="320" href="#320">320</a> <a name="321" href="#321">321</a> <em>/**<em>*</em></em><a name="322" href="#322">322</a> <em> * Constructor.</em><a name="323" href="#323">323</a> <em> * </em><a name="324" href="#324">324</a> <em> * @param f</em><a name="325" href="#325">325</a> <em> * Compressed arcfile to read.</em><a name="326" href="#326">326</a> <em> * @throws IOException</em><a name="327" href="#327">327</a> <em> */</em><a name="328" href="#328">328</a> <strong>public</strong> CompressedARCReader(<strong>final</strong> File f) throws IOException {<a name="329" href="#329">329</a> <strong>this</strong>(f, 0);<a name="330" href="#330">330</a> }<a name="331" href="#331">331</a> <a name="332" href="#332">332</a> <em>/**<em>*</em></em><a name="333" href="#333">333</a> <em> * Constructor.</em><a name="334" href="#334">334</a> <em> * </em><a name="335" href="#335">335</a> <em> * @param f Compressed arcfile to read.</em><a name="336" href="#336">336</a> <em> * @param offset Position at where to start reading file.</em><a name="337" href="#337">337</a> <em> * @throws IOException</em><a name="338" href="#338">338</a> <em> */</em><a name="339" href="#339">339</a> <strong>public</strong> CompressedARCReader(<strong>final</strong> File f, <strong>final</strong> <strong>long</strong> offset)<a name="340" href="#340">340</a> throws IOException {<a name="341" href="#341">341</a> <em class="comment">// Arc file has been tested for existence by time it has come</em><a name="342" href="#342">342</a> <em class="comment">// to here.</em><a name="343" href="#343">343</a> setIn(<strong>new</strong> <a href="../../../../org/archive/io/GzippedInputStream.html">GzippedInputStream</a>(getInputStream(f, offset)));<a name="344" href="#344">344</a> setCompressed((offset == 0));<a name="345" href="#345">345</a> initialize(f.getAbsolutePath());<a name="346" href="#346">346</a> }<a name="347" href="#347">347</a> <a name="348" href="#348">348</a> <em>/**<em>*</em></em><a name="349" href="#349">349</a> <em> * Constructor.</em><a name="350" href="#350">350</a> <em> * </em><a name="351" href="#351">351</a> <em> * @param f Compressed arcfile.</em><a name="352" href="#352">352</a> <em> * @param is InputStream to use.</em><a name="353" href="#353">353</a> <em> * @throws IOException</em><a name="354" href="#354">354</a> <em> */</em><a name="355" href="#355">355</a> <strong>public</strong> CompressedARCReader(<strong>final</strong> String f, <strong>final</strong> InputStream is,<a name="356" href="#356">356</a> <strong>final</strong> <strong>boolean</strong> atFirstRecord)<a name="357" href="#357">357</a> throws IOException {<a name="358" href="#358">358</a> <em class="comment">// Arc file has been tested for existence by time it has come</em><a name="359" href="#359">359</a> <em class="comment">// to here.</em><a name="360" href="#360">360</a> setIn(<strong>new</strong> <a href="../../../../org/archive/io/GzippedInputStream.html">GzippedInputStream</a>(is));<a name="361" href="#361">361</a> setCompressed(<strong>true</strong>);<a name="362" href="#362">362</a> setAlignedOnFirstRecord(atFirstRecord);<a name="363" href="#363">363</a> initialize(f);<a name="364" href="#364">364</a> }<a name="365" href="#365">365</a> <a name="366" href="#366">366</a> <em>/**<em>*</em></em><a name="367" href="#367">367</a> <em> * Get record at passed <code>offset</code>.</em><a name="368" href="#368">368</a> <em> * </em><a name="369" href="#369">369</a> <em> * @param offset</em><a name="370" href="#370">370</a> <em> * Byte index into arcfile at which a record starts.</em><a name="371" href="#371">371</a> <em> * @return An ARCRecord reference.</em><a name="372" href="#372">372</a> <em> * @throws IOException</em><a name="373" href="#373">373</a> <em> */</em><a name="374" href="#374">374</a> <strong>public</strong> <a href="../../../../org/archive/io/arc/ARCRecord.html">ARCRecord</a> get(<strong>long</strong> offset) throws IOException {<a name="375" href="#375">375</a> cleanupCurrentRecord();<a name="376" href="#376">376</a> ((<a href="../../../../org/archive/io/GzippedInputStream.html">GzippedInputStream</a>)getIn()).gzipMemberSeek(offset);<a name="377" href="#377">377</a> <strong>return</strong> createArchiveRecord(getIn(), offset);<a name="378" href="#378">378</a> }<a name="379" href="#379">379</a> <a name="380" href="#380">380</a> <strong>public</strong> Iterator<ArchiveRecord> iterator() {<a name="381" href="#381">381</a> <em>/**<em>*</em></em><a name="382" href="#382">382</a> <em> * Override ARCRecordIterator so can base returned iterator on</em><a name="383" href="#383">383</a> <em> * GzippedInputStream iterator.</em><a name="384" href="#384">384</a> <em> */</em><a name="385" href="#385">385</a> <strong>return</strong> <strong>new</strong> ArchiveRecordIterator() {<a name="386" href="#386">386</a> <strong>private</strong> <a href="../../../../org/archive/io/GzippedInputStream.html">GzippedInputStream</a> gis =<a name="387" href="#387">387</a> (<a href="../../../../org/archive/io/GzippedInputStream.html">GzippedInputStream</a>)getInputStream();<a name="388" href="#388">388</a> <a name="389" href="#389">389</a> <strong>private</strong> Iterator gzipIterator = <strong>this</strong>.gis.iterator();<a name="390" href="#390">390</a> <a name="391" href="#391">391</a> <strong>protected</strong> <strong>boolean</strong> innerHasNext() {<a name="392" href="#392">392</a> <strong>return</strong> <strong>this</strong>.gzipIterator.hasNext();<a name="393" href="#393">393</a> }<a name="394" href="#394">394</a> <a name="395" href="#395">395</a> <strong>protected</strong> <a href="../../../../org/archive/io/ArchiveRecord.html">ArchiveRecord</a> innerNext() throws IOException {<a name="396" href="#396">396</a> <em class="comment">// Get the positoin before gzipIterator.next moves</em><a name="397" href="#397">397</a> <em class="comment">// it on past the gzip header.</em><a name="398" href="#398">398</a> <strong>long</strong> p = <strong>this</strong>.gis.position();<a name="399" href="#399">399</a> InputStream is = (InputStream) <strong>this</strong>.gzipIterator.next();<a name="400" href="#400">400</a> <strong>return</strong> createArchiveRecord(is, p);<a name="401" href="#401">401</a> }<a name="402" href="#402">402</a> };<a name="403" href="#403">403</a> }<a name="404" href="#404">404</a> <a name="405" href="#405">405</a> <strong>protected</strong> <strong>void</strong> gotoEOR(<a href="../../../../org/archive/io/ArchiveRecord.html">ArchiveRecord</a> rec) throws IOException {<a name="406" href="#406">406</a> <strong>long</strong> skipped = ((GzippedInputStream)getIn()).<a name="407" href="#407">407</a> gotoEOR(LINE_SEPARATOR);<a name="408" href="#408">408</a> <strong>if</strong> (skipped <= 0) {<a name="409" href="#409">409</a> <strong>return</strong>;<a name="410" href="#410">410</a> }<a name="411" href="#411">411</a> <em class="comment">// Report on system error the number of unexpected characters</em><a name="412" href="#412">412</a> <em class="comment">// at the end of this record.</em><a name="413" href="#413">413</a> <a href="../../../../org/archive/io/ArchiveRecordHeader.html">ArchiveRecordHeader</a> meta = (getCurrentRecord() != <strong>null</strong>)?<a name="414" href="#414">414</a> rec.getHeader(): <strong>null</strong>;<a name="415" href="#415">415</a> String message = <span class="string">"Record ENDING at "</span> +<a name="416" href="#416">416</a> ((<a href="../../../../org/archive/io/GzippedInputStream.html">GzippedInputStream</a>)getIn()).position() +<a name="417" href="#417">417</a> <span class="string">" has "</span> + skipped + <span class="string">" trailing byte(s): "</span> +<a name="418" href="#418">418</a> ((meta != <strong>null</strong>)? meta.toString(): <span class="string">""</span>);<a name="419" href="#419">419</a> <strong>if</strong> (isStrict()) {<a name="420" href="#420">420</a> <strong>throw</strong> <strong>new</strong> IOException(message);<a name="421" href="#421">421</a> }<a name="422" href="#422">422</a> logStdErr(Level.WARNING, message);<a name="423" href="#423">423</a> }<a name="424" href="#424">424</a> }<a name="425" href="#425">425</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 + -