📄 recordinginputstream.html
字号:
<a name="260" href="#260">260</a> <strong>if</strong> (Thread.interrupted()) {<a name="261" href="#261">261</a> <strong>throw</strong> <strong>new</strong> InterruptedException(<span class="string">"Interrupted during IO"</span>);<a name="262" href="#262">262</a> }<a name="263" href="#263">263</a> } <strong>catch</strong> (SocketTimeoutException e) {<a name="264" href="#264">264</a> <em class="comment">// A socket timeout is just a transient problem, meaning</em><a name="265" href="#265">265</a> <em class="comment">// nothing was available in the configured timeout period,</em><a name="266" href="#266">266</a> <em class="comment">// but something else might become available later.</em><a name="267" href="#267">267</a> <em class="comment">// Take this opportunity to check the overall </em><a name="268" href="#268">268</a> <em class="comment">// timeout (below). One reason for this timeout is </em><a name="269" href="#269">269</a> <em class="comment">// servers that keep up the connection, 'keep-alive', even</em><a name="270" href="#270">270</a> <em class="comment">// though we asked them to not keep the connection open.</em><a name="271" href="#271">271</a> <strong>if</strong> (System.currentTimeMillis() < timeoutTime) {<a name="272" href="#272">272</a> <strong>if</strong> (logger.isLoggable(Level.FINE)) {<a name="273" href="#273">273</a> logger.fine(<span class="string">"Socket timed out after "</span> +<a name="274" href="#274">274</a> (timeoutTime - startTime) + <span class="string">"ms: "</span> +<a name="275" href="#275">275</a> e.getMessage());<a name="276" href="#276">276</a> }<a name="277" href="#277">277</a> }<a name="278" href="#278">278</a> } <strong>catch</strong> (SocketException se) {<a name="279" href="#279">279</a> <strong>throw</strong> se;<a name="280" href="#280">280</a> } <strong>catch</strong> (NullPointerException e) {<a name="281" href="#281">281</a> <em class="comment">// [ 896757 ] NPEs in Andy's Th-Fri Crawl.</em><a name="282" href="#282">282</a> <em class="comment">// A crawl was showing NPE's in this part of the code but can</em><a name="283" href="#283">283</a> <em class="comment">// not reproduce. Adding this rethrowing catch block w/</em><a name="284" href="#284">284</a> <em class="comment">// diagnostics to help should we come across the problem in the</em><a name="285" href="#285">285</a> <em class="comment">// future.</em><a name="286" href="#286">286</a> <strong>throw</strong> <strong>new</strong> NullPointerException(<span class="string">"Stream "</span> + <strong>this</strong>.in + <span class="string">", "</span> +<a name="287" href="#287">287</a> e.getMessage() + <span class="string">" "</span> + Thread.currentThread().getName());<a name="288" href="#288">288</a> }<a name="289" href="#289">289</a> <strong>if</strong> (System.currentTimeMillis() >= timeoutTime) {<a name="290" href="#290">290</a> <strong>throw</strong> <strong>new</strong> <a href="../../../org/archive/io/RecorderTimeoutException.html">RecorderTimeoutException</a>(<span class="string">"Timedout after "</span> +<a name="291" href="#291">291</a> (timeoutTime - startTime) + <span class="string">"ms."</span>);<a name="292" href="#292">292</a> }<a name="293" href="#293">293</a> <strong>if</strong> (hardMaxLength > 0 && totalBytes >= hardMaxLength) {<a name="294" href="#294">294</a> <strong>throw</strong> <strong>new</strong> <a href="../../../org/archive/io/RecorderLengthExceededException.html">RecorderLengthExceededException</a>();<a name="295" href="#295">295</a> }<a name="296" href="#296">296</a> <strong>if</strong> (maxLength > 0 && totalBytes >= maxLength) {<a name="297" href="#297">297</a> <strong>break</strong>; <em class="comment">// return</em><a name="298" href="#298">298</a> }<a name="299" href="#299">299</a> }<a name="300" href="#300">300</a> }<a name="301" href="#301">301</a> <a name="302" href="#302">302</a> <strong>public</strong> <strong>long</strong> getSize() {<a name="303" href="#303">303</a> <strong>return</strong> <strong>this</strong>.recordingOutputStream.getSize();<a name="304" href="#304">304</a> }<a name="305" href="#305">305</a> <a name="306" href="#306">306</a> <strong>public</strong> <strong>void</strong> markContentBegin() {<a name="307" href="#307">307</a> <strong>this</strong>.recordingOutputStream.markContentBegin();<a name="308" href="#308">308</a> }<a name="309" href="#309">309</a> <a name="310" href="#310">310</a> <strong>public</strong> <strong>void</strong> startDigest() {<a name="311" href="#311">311</a> <strong>this</strong>.recordingOutputStream.startDigest();<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> * Convenience method for setting SHA1 digest.</em><a name="316" href="#316">316</a> <em> */</em><a name="317" href="#317">317</a> <strong>public</strong> <strong>void</strong> setSha1Digest() {<a name="318" href="#318">318</a> <strong>this</strong>.recordingOutputStream.setSha1Digest();<a name="319" href="#319">319</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> * Sets a digest function which may be applied to recorded data.</em><a name="323" href="#323">323</a> <em> * As usually only a subset of the recorded data should</em><a name="324" href="#324">324</a> <em> * be fed to the digest, you must also call startDigest()</em><a name="325" href="#325">325</a> <em> * to begin digesting.</em><a name="326" href="#326">326</a> <em> *</em><a name="327" href="#327">327</a> <em> * @param md</em><a name="328" href="#328">328</a> <em> */</em><a name="329" href="#329">329</a> <strong>public</strong> <strong>void</strong> setDigest(MessageDigest md) {<a name="330" href="#330">330</a> <strong>this</strong>.recordingOutputStream.setDigest(md);<a name="331" href="#331">331</a> }<a name="332" href="#332">332</a> <a name="333" href="#333">333</a> <em>/**<em>*</em></em><a name="334" href="#334">334</a> <em> * Return the digest value for any recorded, digested data. Call</em><a name="335" href="#335">335</a> <em> * only after all data has been recorded; otherwise, the running</em><a name="336" href="#336">336</a> <em> * digest state is ruined.</em><a name="337" href="#337">337</a> <em> *</em><a name="338" href="#338">338</a> <em> * @return the digest final value</em><a name="339" href="#339">339</a> <em> */</em><a name="340" href="#340">340</a> <strong>public</strong> byte[] getDigestValue() {<a name="341" href="#341">341</a> <strong>return</strong> <strong>this</strong>.recordingOutputStream.getDigestValue();<a name="342" href="#342">342</a> }<a name="343" href="#343">343</a> <a name="344" href="#344">344</a> <strong>public</strong> <a href="../../../org/archive/io/ReplayCharSequence.html">ReplayCharSequence</a> getReplayCharSequence() throws IOException {<a name="345" href="#345">345</a> <strong>return</strong> getReplayCharSequence(<strong>null</strong>);<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> * @param characterEncoding Encoding of recorded stream.</em><a name="350" href="#350">350</a> <em> * @return A ReplayCharSequence Will return null if an IOException. Call</em><a name="351" href="#351">351</a> <em> * close on returned RCS when done.</em><a name="352" href="#352">352</a> <em> * @throws IOException</em><a name="353" href="#353">353</a> <em> */</em><a name="354" href="#354">354</a> <strong>public</strong> <a href="../../../org/archive/io/ReplayCharSequence.html">ReplayCharSequence</a> getReplayCharSequence(String characterEncoding)<a name="355" href="#355">355</a> throws IOException {<a name="356" href="#356">356</a> <strong>return</strong> <strong>this</strong>.recordingOutputStream.<a name="357" href="#357">357</a> getReplayCharSequence(characterEncoding);<a name="358" href="#358">358</a> }<a name="359" href="#359">359</a> <a name="360" href="#360">360</a> <strong>public</strong> <strong>long</strong> getResponseContentLength() {<a name="361" href="#361">361</a> <strong>return</strong> <strong>this</strong>.recordingOutputStream.getResponseContentLength();<a name="362" href="#362">362</a> }<a name="363" href="#363">363</a> <a name="364" href="#364">364</a> <strong>public</strong> <strong>void</strong> closeRecorder() throws IOException {<a name="365" href="#365">365</a> <strong>this</strong>.recordingOutputStream.closeRecorder();<a name="366" href="#366">366</a> }<a name="367" href="#367">367</a> <a name="368" href="#368">368</a> <em>/**<em>*</em></em><a name="369" href="#369">369</a> <em> * @param tempFile</em><a name="370" href="#370">370</a> <em> * @throws IOException</em><a name="371" href="#371">371</a> <em> */</em><a name="372" href="#372">372</a> <strong>public</strong> <strong>void</strong> copyContentBodyTo(File tempFile) throws IOException {<a name="373" href="#373">373</a> FileOutputStream fos = <strong>new</strong> FileOutputStream(tempFile);<a name="374" href="#374">374</a> <a href="../../../org/archive/io/ReplayInputStream.html">ReplayInputStream</a> ris = getContentReplayInputStream();<a name="375" href="#375">375</a> ris.readFullyTo(fos);<a name="376" href="#376">376</a> fos.close();<a name="377" href="#377">377</a> ris.close();<a name="378" href="#378">378</a> }<a name="379" href="#379">379</a> <a name="380" href="#380">380</a> <em>/**<em>*</em></em><a name="381" href="#381">381</a> <em> * @return True if we've been opened.</em><a name="382" href="#382">382</a> <em> */</em><a name="383" href="#383">383</a> <strong>public</strong> <strong>boolean</strong> isOpen()<a name="384" href="#384">384</a> {<a name="385" href="#385">385</a> <strong>return</strong> <strong>this</strong>.in != <strong>null</strong>;<a name="386" href="#386">386</a> }<a name="387" href="#387">387</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 + -