public InputStream getResponseAsStream() { if(closed) throw new IllegalStateException("HTTPMethod: method is closed"); if(this.methodstream != null) { // duplicate: caller's problem HTTPSession.log.warn("HTTPRequest.getResponseBodyAsStream: Getting method stream multiple times"); } else { // first time HTTPMethodStream stream = null; try { if(response == null) return null; stream = new HTTPMethodStream(response.getEntity().getContent(), this); } catch (Exception e) { stream = null; } this.methodstream = stream; } return this.methodstream; }
HTTPMethodStream stream = (HTTPMethodStream) method.getResponseBodyAsStream(); Assert.assertTrue(method.hasStreamOpen()); stream.close(); Assert.assertTrue(method.isClosed()); Assert.assertFalse(method.hasStreamOpen()); stream = (HTTPMethodStream) method.getResponseBodyAsStream(); method.close(); Assert.assertTrue(stream.isClosed()); Assert.assertFalse(method.hasStreamOpen()); Assert.assertTrue(method.isClosed()); stream = (HTTPMethodStream) method.getResponseBodyAsStream(); session.close(); Assert.assertTrue(stream.isClosed()); Assert.assertTrue(method.isClosed()); methodcount = session.getMethodcount(); readbinaryfile(stream); System.err.println("Stream not closed."); Assert.assertFalse(stream.isClosed()); } catch (Exception e) { Assert.assertFalse(method.hasStreamOpen());
/** * Calling close will force the method to close, and will * force any open stream to terminate. If the session is local, * Then that too will be closed. */ public synchronized void close() { if(closed) return; // multiple calls ok closed = true; // mark as closed to prevent recursive calls if(methodstream != null) { try { methodstream.close(); } catch (IOException ioe) {/*failure is ok*/} ; methodstream = null; } if(this.request != null) { this.request.releaseConnection(); this.request = null; } if(session != null) { session.removeMethod(this); if(localsession) { session.close(); session = null; } } }
/** * Closes this input stream and releases any system resources associated * with the stream; closes the method also. * * @exception IOException if an I/O error occurs; but not if close * is called twice. */ @Override public void close() throws IOException { if(closed) return; /* Allow multiple close calls */ closed = true; try { consume(); } finally { super.close(); } if(method != null) method.close(); }
if(methodstream != null) { try { this.methodstream.close(); // May recursr } catch (IOException ioe) {/*failure is ok*/} this.methodstream = null;
/** * Closes this input stream and releases any system resources associated * with the stream; closes the method also. * * @exception IOException if an I/O error occurs; but not if close * is called twice. */ @Override public void close() throws IOException { if(closed) return; /* Allow multiple close calls */ closed = true; try { consume(); } finally { super.close(); } if(method != null) method.close(); }
public InputStream getResponseAsStream() { if(closed) throw new IllegalStateException("HTTPMethod: method is closed"); if(!executed) throw new IllegalStateException("HTTPMethod: method has not been executed"); if(this.methodstream != null) { // duplicate: caller's problem HTTPSession.log.warn("HTTPRequest.getResponseBodyAsStream: Getting method stream multiple times"); } else { // first time HTTPMethodStream stream = null; try { if(this.lastresponse == null) return null; stream = new HTTPMethodStream(this.lastresponse.getEntity().getContent(), this); } catch (Exception e) { stream = null; } this.methodstream = stream; } return this.methodstream; }