List of usage examples for org.apache.http.util EntityUtils toByteArray
public static byte[] toByteArray(HttpEntity httpEntity) throws IOException
From source file:edu.uci.ics.crawler4j.crawler.Page.java
/** * Loads the content of this page from a fetched * HttpEntity. */ public void load(HttpEntity entity) throws Exception { contentType = null;/* w ww.j a va 2s. c om*/ Header type = entity.getContentType(); if (type != null) { contentType = type.getValue(); } contentEncoding = null; Header encoding = entity.getContentEncoding(); if (encoding != null) { contentEncoding = encoding.getValue(); } Charset charset = ContentType.getOrDefault(entity).getCharset(); if (charset != null) { contentCharset = charset.displayName(); } contentData = EntityUtils.toByteArray(entity); }
From source file:de.yaio.commons.http.HttpUtils.java
/** * execute GET-Request for url with params * @param baseUrl the url to call * @param username username for auth * @param password password for auth * @param params params for the request * @return Response-Text as ByteArray * @throws IOException possible Exception if Request-state <200 > 299 */// w w w . j a v a2 s . co m public static byte[] callGetUrl(final String baseUrl, final String username, final String password, final Map<String, String> params) throws IOException { HttpResponse response = callGetUrlPure(baseUrl, username, password, params); int retCode = response.getStatusLine().getStatusCode(); if (retCode < 200 || retCode > 299) { throw new IOException("illegal reponse:" + response.getStatusLine() + " for urlcall:" + baseUrl); } HttpEntity entity = response.getEntity(); return EntityUtils.toByteArray(entity); }
From source file:co.com.soinsoftware.altablero.utils.HttpRequest.java
@Override public Object handleResponse(HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); final ContentType contentType = ContentType.getOrDefault(entity); if (contentType.getMimeType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { InputStream inputStream = null; byte[] zipInBytes = EntityUtils.toByteArray(entity); if (zipInBytes != null) { inputStream = new ByteArrayInputStream(zipInBytes); }/*from ww w. ja v a 2 s . com*/ return inputStream; } return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException(EXCEPTION_MESSAGE + status); } }
From source file:org.apache.gobblin.http.ApacheHttpResponseHandler.java
private byte[] getEntityAsByteArray(HttpEntity entity) { try {//from w w w. ja v a 2s.c om return EntityUtils.toByteArray(entity); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.cisco.oss.foundation.http.apache.ApacheHttpResponse.java
@Override public byte[] getResponse() { if (hasResponseBody()) { if (!isClosed) { try { return EntityUtils.toByteArray(httpResponse.getEntity()); } catch (IOException e) { throw new ClientException(e.toString(), e); }/* w w w .j a v a 2 s .co m*/ } else { return responseBody; } } else { return new byte[0]; } }
From source file:org.artags.android.app.stackwidget.util.HttpUtils.java
public static Bitmap loadBitmap(String url) { try {/* w w w . j a v a 2 s . c o m*/ final HttpClient httpClient = getHttpClient(); final HttpResponse resp = httpClient.execute(new HttpGet(url)); final HttpEntity entity = resp.getEntity(); final int statusCode = resp.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK || entity == null) { return null; } final byte[] respBytes = EntityUtils.toByteArray(entity); // Decode the bytes and return the bitmap. BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); decodeOptions.inSampleSize = 1; return BitmapFactory.decodeByteArray(respBytes, 0, respBytes.length, decodeOptions); } catch (Exception e) { Log.w(TAG, "Problem while loading image: " + e.toString(), e); } return null; }
From source file:com.subgraph.vega.ui.httpviewer.entity.HttpEntityViewer.java
public void displayHttpEntity(HttpEntity entity) { currentlyDisplayedEntity = entity;/*from www .j a v a2s . c om*/ if (entity == null || entity.getContentLength() == 0) { displayEmptyViewer(); return; } try { final String asString = EntityUtils.toString(entity); final String contentType = contentType(entity); final String contentEncoding = contentEncoding(entity); if (isBodyAscii(asString)) { displayTextViewer(asString, contentType, contentEncoding); return; } byte[] binary = EntityUtils.toByteArray(entity); if (binary == null || binary.length == 0) { displayEmptyViewer(); return; } final ImageData imageData = binaryToImageData(binary); if (imageData != null) { displayImageViewer(imageData, binary, contentType, contentEncoding); } else { displayHexViewer(binary, contentType, contentEncoding); } } catch (ParseException e) { displayEmptyViewer(); } catch (IOException e) { displayEmptyViewer(); } }
From source file:com.subgraph.vega.internal.model.requests.HttpMessageCloner.java
private HttpEntity copyEntity(HttpEntity entity) { try {//from w ww . j a va 2s .c o m if (entity == null) { return null; } final byte[] content = EntityUtils.toByteArray(entity); return new RequestLogEntity(content, entity.getContentType(), entity.getContentEncoding()); } catch (IOException e) { return null; } }
From source file:com.autonomousturk.crawler.Page.java
/** * Loads the content of this page from a fetched * HttpEntity./*from ww w . j av a2s . c o m*/ */ public void load(HttpEntity entity) throws Exception { contentType = null; Header type = entity.getContentType(); if (type != null) { contentType = type.getValue(); } contentEncoding = null; Header encoding = entity.getContentEncoding(); if (encoding != null) { contentEncoding = encoding.getValue(); } Charset charset = ContentType.getOrDefault(entity).getCharset(); if (charset != null) { contentCharset = charset.displayName(); } contentData = EntityUtils.toByteArray(entity); }