List of usage examples for org.apache.http.util EntityUtils toByteArray
public static byte[] toByteArray(HttpEntity httpEntity) throws IOException
From source file:com.aspire.mandou.framework.http.BetterHttpResponseImpl.java
@Override public byte[] getResponseBodyAsBytes() throws IOException { return EntityUtils.toByteArray(entity); }
From source file:me.zhuoran.crawler4j.crawler.http.HttpFetchResult.java
public HttpFetchResult(HttpResponse rep, String defaultCharset) throws Exception { entity = rep.getEntity();/*from w w w .j av a2s.c o m*/ status = rep.getStatusLine(); this.charset = defaultCharset; if (entity.getContentType() != null && entity.getContentType().getValue().contains("text/html")) { html = EntityUtils.toString(entity, charset); } else { contentData = EntityUtils.toByteArray(entity); } }
From source file:com.agileapes.couteau.http.util.HttpEntityByteArrayTransformer.java
@Override public byte[] map(HttpEntity input) { try {/*from w w w. j av a2 s . co m*/ return EntityUtils.toByteArray(input); } catch (IOException e) { return null; } }
From source file:com.github.grantjforrester.bdd.rest.httpclient.HttpClientResponse.java
public byte[] getContent() { try {//from ww w . jav a2s . c om return EntityUtils.toByteArray(httpResponse.getEntity()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.net.plus.common.http.handler.ByteArrayResponseHandler.java
/** * Returns the response body as a byte array if the response was successful (a * 2xx status code). If no response body exists, this returns null. If the * response was unsuccessful (>= 300 status code), throws an * {@link HttpResponseException}.// w ww . ja va 2s . c o m */ public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } byte[] result = null; long len = entity.getContentLength(); if (len != -1 && len < 4096) { result = EntityUtils.toByteArray(entity); } else { result = Util.toByteArray(entity); } EntityUtils.consume(entity); return result; }
From source file:com.github.ignition.support.http.IgnitedHttpResponseImpl.java
@Override public byte[] getResponseBodyAsBytes() throws IOException { if (entity == null) { return null; }// www . ja va 2 s . c o m return EntityUtils.toByteArray(entity); }
From source file:com.grouzen.android.serenity.Response.java
private byte[] readData(HttpResponse response) throws IOException { if (response != null) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toByteArray(response.getEntity()); }/*from www .j ava 2s. c om*/ throw new IOException("Bad http status: " + response.getStatusLine().getStatusCode()); } throw new IOException("Bad response"); }
From source file:net.nordist.lloydproof.HttpJSONClient.java
public JSONObject parseResponse() throws UnsupportedEncodingException, JSONException, IOException { byte[] body = EntityUtils.toByteArray(httpResponse.getEntity()); return new JSONObject(new String(body, "UTF-8")); }
From source file:com.messagemedia.restapi.client.v1.internal.RestResponse.java
public RestResponse(HttpResponse response) throws RestApiException { this.resultCode = response.getStatusLine().getStatusCode(); for (Header header : response.getAllHeaders()) { headers.put(header.getName(), header.getValue()); }/*from w ww . j av a 2 s .c o m*/ if (response.getEntity() != null) { try { this.resultBytes = EntityUtils.toByteArray(response.getEntity()); } catch (IOException e) { throw new RestApiException("Error reading response", e); } finally { EntityUtils.consumeQuietly(response.getEntity()); } } }
From source file:neembuu.uploader.captcha.ImagePanel.java
public final void update(URL imageFileUrl, HttpContext httpContext) { try {//from w w w.j a va 2 s . c o m HttpClient httpClient = NUHttpClient.getHttpClient(); HttpGet httpGet = new HttpGet(imageFileUrl.toURI()); HttpResponse httpresponse = httpClient.execute(httpGet, httpContext); byte[] imageInByte = EntityUtils.toByteArray(httpresponse.getEntity()); InputStream in = new ByteArrayInputStream(imageInByte); image = ImageIO.read(in); //image = ImageIO.read(imageFileUrl); } catch (Exception ex) { NULogger.getLogger().log(Level.INFO, "ImagePanel exception: {0}", ex.getMessage()); } }