List of usage examples for org.apache.http.entity BasicHttpEntity setContentLength
public void setContentLength(long j)
From source file:org.springframework.cloud.netflix.ribbon.apache.HttpClientUtils.java
/** * Creates an new {@link HttpEntity} by copying the {@link HttpEntity} from the {@link HttpResponse}. * This method will close the response after copying the entity. * @param response The response to create the {@link HttpEntity} from * @return A new {@link HttpEntity}/*from w w w. j av a 2 s.c o m*/ * @throws IOException thrown if there is a problem closing the response. */ public static HttpEntity createEntity(HttpResponse response) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(EntityUtils.toByteArray(response.getEntity())); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(is); entity.setContentLength(response.getEntity().getContentLength()); if (CloseableHttpResponse.class.isInstance(response)) { ((CloseableHttpResponse) response).close(); } return entity; }
From source file:net.kungfoo.grizzly.proxy.impl.ProxyAdapter.java
private static HttpRequest convert(String method, String uri, Request request) { HttpRequest req;/*www .j av a 2 s. co m*/ final int len = request.getContentLength(); if (len > 0) { req = new BasicHttpEntityEnclosingRequest(method, uri); final BasicHttpEntity httpEntity = new BasicHttpEntity(); httpEntity.setContentLength(len); // httpEntity.setContent(((InternalInputBuffer) request.getInputBuffer()).getInputStream()); ((BasicHttpEntityEnclosingRequest) req).setEntity(httpEntity); } else { req = new BasicHttpRequest(method, uri); } final MimeHeaders mimeHeaders = request.getMimeHeaders(); final Enumeration names = mimeHeaders.names(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); req.addHeader(name, mimeHeaders.getHeader(name)); } return req; }
From source file:com.orange.retrytest.OkHttpStack.java
private static HttpEntity getEntity(Response response) throws IOException { BasicHttpEntity entity = new BasicHttpEntity(); ResponseBody body = response.body(); entity.setContent(body.byteStream()); entity.setContentLength(body.contentLength()); entity.setContentEncoding(response.header("Content-Encoding")); if (body.contentType() != null) { entity.setContentType(body.contentType().type()); }//from w ww.j a v a2 s . c o m return entity; }
From source file:com.aix.city.comm.OkHttpStack.java
private static HttpEntity entityFromOkHttpResponse(Response r) throws IOException { BasicHttpEntity entity = new BasicHttpEntity(); ResponseBody body = r.body();//from w ww . j a v a 2 s . com entity.setContent(body.byteStream()); entity.setContentLength(body.contentLength()); entity.setContentEncoding(r.header("Content-Encoding")); if (body.contentType() != null) { entity.setContentType(body.contentType().type()); } return entity; }
From source file:com.objectivetruth.uoitlibrarybooking.app.networking.OkHttp3Stack.java
private static HttpEntity entityFromOkHttpResponse(Response r) throws IOException { BasicHttpEntity entity = new BasicHttpEntity(); ResponseBody body = r.body();/*from w w w. ja va 2 s .c o m*/ entity.setContent(body.byteStream()); entity.setContentLength(body.contentLength()); entity.setContentEncoding(r.header("Content-Encoding")); if (body.contentType() != null) { entity.setContentType(body.contentType().type()); } return entity; }
From source file:com.phattn.vnexpressnews.io.OkHttpStack.java
private static HttpEntity entityFromOkHttpResponse(Response response) throws IOException { BasicHttpEntity entity = new BasicHttpEntity(); ResponseBody body = response.body(); entity.setContent(body.byteStream()); entity.setContentLength(body.contentLength()); entity.setContentEncoding(response.header("Content-Encoding")); if (body.contentType() != null) { entity.setContentType(body.contentType().type()); }//ww w. j ava2s . co m return entity; }
From source file:com.yangcong345.android.phone.manager.OkHttpStack.java
/** * Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}. * * @return an HttpEntity populated with data from <code>connection</code>. */// w w w. j a v a 2 s.c o m private static HttpEntity entityFromOkHttp(Response okResponse) { ResponseBody rb = okResponse.body(); BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream = rb.byteStream(); entity.setContent(inputStream); entity.setContentLength(rb.contentLength()); entity.setContentType(rb.contentType().type()); return entity; }
From source file:com.aerofs.baseline.http.TestHttpRequestHandler.java
private static HttpPost newChunkedPost(String resource, byte[] bytes) { BasicHttpEntity basic = new BasicHttpEntity(); basic.setChunked(true);/*from w w w. j av a 2 s . co m*/ basic.setContentLength(-1); basic.setContent(new ByteArrayInputStream(bytes)); HttpPost post = new HttpPost(ServiceConfiguration.SERVICE_URL + "/" + resource); post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM); post.setEntity(basic); return post; }
From source file:com.eTilbudsavis.etasdk.network.impl.HttpURLNetwork.java
private static HttpEntity getEntity(HttpURLConnection connection) { BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream;/* w w w . j av a 2 s. c o m*/ try { inputStream = connection.getInputStream(); } catch (IOException ioe) { inputStream = connection.getErrorStream(); } entity.setContent(inputStream); entity.setContentLength(connection.getContentLength()); entity.setContentEncoding(connection.getContentEncoding()); entity.setContentType(connection.getContentType()); return entity; }
From source file:com.androidso.lib.net.http.OkHttpStack.java
private static HttpEntity entityFromOkHttpResponse(Response r) throws IOException { BasicHttpEntity entity = new BasicHttpEntity() { @Override// w ww . j a va 2s . co m public void consumeContent() { // getContent().close(); } }; ResponseBody body = r.body(); entity.setContent(body.byteStream()); entity.setContentLength(body.contentLength()); entity.setContentEncoding(r.header("Content-Encoding")); if (body.contentType() != null) { entity.setContentType(body.contentType().type()); } return entity; }