InputStream instream = getResponseBodyAsStream(); if (instream != null) { long contentLength = getResponseContentLength();
if (maxlen < 0) throw new IllegalArgumentException("maxlen must be positive"); if (this.responseBody == null) { InputStream instream = getResponseBodyAsStream(); if (instream != null) {
private InputStream createConnectionReleasingInputStream(final HttpMethodBase method) throws IOException { return new FilterInputStream(method.getResponseBodyAsStream()) { public void close() throws IOException { try { super.close(); } finally { method.releaseConnection(); } } }; }
private InputStream createConnectionReleasingInputStream(final HttpMethodBase method) throws IOException { return new FilterInputStream(method.getResponseBodyAsStream()) { public void close() throws IOException { try { super.close(); } finally { method.releaseConnection(); } } }; }
private HttpClientReleasingInputStream(HttpMethodBase httpRequest) throws IOException { super(httpRequest.getResponseBodyAsStream()); this.httpRequest = httpRequest; }
private InputStream createConnectionReleasingInputStream(final HttpMethodBase method) throws IOException { return new FilterInputStream(method.getResponseBodyAsStream()) { public void close() throws IOException { try { super.close(); } finally { method.releaseConnection(); } } }; }
private HttpClientReleasingInputStream(HttpMethodBase httpRequest) throws IOException { super(httpRequest.getResponseBodyAsStream()); this.httpRequest = httpRequest; }
@Override public InputStream getResponseContent() throws IOException { return method.getResponseBodyAsStream(); }
protected void discardBody(HttpMethodBase method) throws IOException { InputStream body = method.getResponseBodyAsStream(); if (body != null) { OutputStream out = new ByteArrayOutputStream(); IOUtils.copy(body, out); out.close(); } }
/** Return m's response body as a string, optionally limiting the length that we read * @param maxLength if 0, no limit */ public static String getResponseBodyAsStream(HttpMethodBase m, int maxLength) throws IOException { final InputStream is = m.getResponseBodyAsStream(); final StringBuilder content = new StringBuilder(); final String charset = m.getResponseCharSet(); final byte [] buffer = new byte[16384]; int n = 0; while( (n = is.read(buffer, 0, buffer.length)) > 0) { content.append(new String(buffer, 0, n, charset)); if(maxLength != 0 && content.length() > maxLength) { throw new IllegalArgumentException("Response body size is over maxLength (" + maxLength + ")"); } } return content.toString(); }
protected String getBody(HttpMethodBase method) throws IOException { StringBuilder builder = new StringBuilder(); InputStream body = method.getResponseBodyAsStream(); if (body != null) {; Reader reader = new InputStreamReader(body, "UTF-8"); try { copy(reader, builder); } finally { reader.close(); } } return builder.toString(); }
public InputStream getResponseAsStream() { if(closed) throw new IllegalStateException("HTTPMethod: method is closed"); if(this.methodstream != null) { // duplicate: caller's problem HTTPSession.log.warn("HTTPMethod.getResponseBodyAsStream: Getting method stream multiple times"); } else { // first time HTTPMethodStream stream = null; try { if(method == null) return null; stream = new HTTPMethodStream(method.getResponseBodyAsStream(), this); } catch (Exception e) { stream = null; } this.methodstream = stream; } return this.methodstream; }
/** * Constructs an appropriate WebResponseData. * May be overridden by subclasses to return a specialized WebResponseData. * @param statusMessage StatusMessage from the response * @param headers response headers * @param statusCode response status code * @param method request method * @return the WebResponseData to use for this response * @throws IOException if there is a problem reading the response body */ protected WebResponseData newWebResponseDataInstance( final String statusMessage, final List<NameValuePair> headers, final int statusCode, final HttpMethodBase method ) throws IOException { return new WebResponseData(method.getResponseBodyAsStream(), statusCode, statusMessage, headers); }
/** * Constructs an appropriate WebResponseData. * May be overridden by subclasses to return a specialized WebResponseData. * @param statusMessage StatusMessage from the response * @param headers response headers * @param statusCode response status code * @param method request method * @return the WebResponseData to use for this response * @throws IOException if there is a problem reading the response body */ protected WebResponseData newWebResponseDataInstance( final String statusMessage, final List<NameValuePair> headers, final int statusCode, final HttpMethodBase method ) throws IOException { return new WebResponseData(method.getResponseBodyAsStream(), statusCode, statusMessage, headers); }
protected InputStream getInputStream() throws XmlRpcException { try { return method.getResponseBodyAsStream(); } catch (HttpException e) { throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e); } }
private DownloadResponse executeDownloadRequest(final HttpMethodBase request, final File outputFile) throws IOException { int status = getClient().executeMethod(request); return parseDownloadResponse(status, request.getStatusText(), request.getResponseBodyAsStream(), outputFile); }
private Transferable initBasicResponseTransferable(HttpMethodBase method) throws IOException, HttpException { m_client.executeMethod(method); Header contentTypeHeader = method.getResponseHeader("Content-Type"); String contentType = contentTypeHeader != null ? contentTypeHeader.getValue() : ""; Transferable trans = TransferableFactory.getInstance().createStreamTransferable(contentType, method.getResponseBodyAsStream(), method.getResponseCharSet()); return trans; }
private SimpleResponse executeSimpleRequest(final HttpMethodBase request) throws IOException { int status = getClient().executeMethod(request); return parseSimpleResponse(status, request.getStatusText(), request.getResponseBodyAsStream(), request.getResponseCharSet()); }
private DetailedResponse executeDetailedRequest(final HttpMethodBase request, final ResponseProgressListener listener) throws IOException { int status = getClient().executeMethod(request); return parseDetailedResponse(status, request.getStatusText(), request.getResponseBodyAsStream(), request.getResponseCharSet(), listener); }
private ListResponse executeListRequest(final HttpMethodBase request) throws IOException { int status = getClient().executeMethod(request); return parseListResponse(status, request.getStatusText(), request.getResponseBodyAsStream(), request.getResponseCharSet()); }