Android HttpEntity - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HttpEntity class.

This code example shows how to use the following methods: consumeContent, getContent, getContentLength
 
            HttpEntity entity = response.getEntity();
            byte[] body = null;
            if (entity != null) {
                try { 
                    if (entity.getContentLength() > 0) {
                        body = new byte[(int) entity.getContentLength()];
                        DataInputStream dis = new DataInputStream(entity.getContent());
                        try { 
                            dis.readFully(body);
                        } finally { 
                            try { 
                                dis.close();
                            } catch (IOException e) {
                                Log.e(TAG, "Unexpected IOException.", e);
                            } 
                        } 
                    } 
                } finally { 
                    if (entity != null) {

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: consumeContent, getContent, getContentLength
 
    return client;
  } 
 
  protected static byte[] parseResponse(HttpEntity entity) throws IOException {
    if (entity == null || entity.getContentLength() == 0)
      throw new IOException("Null response");
 
    if (entity.getContentLength() < 0)
      throw new IOException("Unknown content length!");
 
    byte[] responseBytes            = new byte[(int)entity.getContentLength()];
    DataInputStream dataInputStream = new DataInputStream(entity.getContent());
    dataInputStream.readFully(responseBytes);
    dataInputStream.close();
 
    entity.consumeContent();
    return responseBytes;
  } 
 

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getContent
 
	/* (non-Javadoc) 
	 * @see org.apache.http.HttpEntity#getContent() 
	 */ 
	public InputStream getContent() throws IOException, IllegalStateException {
		return entity.getContent();
	} 
 
	/* (non-Javadoc) 
	 * @see org.apache.http.HttpEntity#getContentEncoding() 
	 */ 
	public Header getContentEncoding() {
		return entity.getContentEncoding();
	} 
 
	/* (non-Javadoc) 
	 * @see org.apache.http.HttpEntity#isChunked() 
	 */ 
	public boolean isChunked() { 
		return entity.isChunked();
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: consumeContent, getContent, getContentLength
 
            HttpEntity entity = response.getEntity();
            byte[] body = null;
            if (entity != null) {
                try { 
                    if (entity.getContentLength() > 0) {
                        body = new byte[(int) entity.getContentLength()];
                        DataInputStream dis = new DataInputStream(entity.getContent());
                        try { 
                            dis.readFully(body);
                        } finally { 
                            try { 
                                dis.close();
                            } catch (IOException e) {
                                Log.e(TAG, "Unexpected IOException.", e);
                            } 
                        } 
                    } 
                } finally { 
                    if (entity != null) {

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getContentEncoding, getContentLength, getContentType, isChunked
        response.addHeader(HTTP.CONTENT_ENCODING, "identity");
        Mockito.when(session.channel()).thenReturn(channel);
 
        final HttpEntity entity = conn.prepareDecoder(response);
        Assert.assertNotNull(entity);
        Assert.assertEquals(10, entity.getContentLength());
        Assert.assertFalse(entity.isChunked());
        Assert.assertNotNull(entity.getContentType());
        Assert.assertEquals("stuff", entity.getContentType().getValue());
        Assert.assertNotNull(entity.getContentEncoding());
        Assert.assertEquals("identity", entity.getContentEncoding().getValue());
        Assert.assertTrue(conn.contentDecoder instanceof LengthDelimitedDecoder);
    } 
 
    @Test 
    public void testPrepareChunkDecoder() throws Exception { 
        final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader(HTTP.TRANSFER_ENCODING, "chunked");
        response.addHeader(HTTP.CONTENT_TYPE, "stuff");
        response.addHeader(HTTP.CONTENT_ENCODING, "identity");
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getContent
     * @return An input stream that will return the response body when read 
     * @throws IOException if the stream could not be created 
     */ 
    public InputStream getResponseBodyAsStream () throws IOException
    { 
        return entity.getContent();
    } 
 
    /** 
     * Get the body of the response as a byte array 
     * 
     * @return The body of the response. 
     * @throws IOException if an error occurs reading the input stream 
     */ 
    public byte[] getResponseBody () throws IOException 
    { 
        return EntityUtils.toByteArray(entity);
    } 
 
    /** 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getContent, getContentLength, getContentType
		 
		//We support empty body... until we can't anymore 
		if(body != null)	{
			 
			// Make sure the  
			if(body.getContentType() != null)	{
				 
				// If we have json in the type, we're ok 
				if(body.getContentType().getValue().contains("json"))	{
					try { 
						CharBuffer buffer = CharBuffer.allocate((int)body.getContentLength());
						InputStreamReader reader = new InputStreamReader( body.getContent() );
						reader.read(buffer);
						this.array = new JSONArray(buffer.toString());
						converted = false;
					} catch (Exception e) {
						Logger.getLogger(JsonBackedModel.class.getName()).warning("Invalid request response received. Problem reading json content");
						array = null;
					} 
				} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: consumeContent, getContent, getContentLength
 
            HttpEntity entity = response.getEntity();
            byte[] body = null;
            if (entity != null) {
                try { 
                    if (entity.getContentLength() > 0) {
                        body = new byte[(int) entity.getContentLength()];
                        DataInputStream dis = new DataInputStream(entity.getContent());
                        try { 
                            dis.readFully(body);
                        } finally { 
                            try { 
                                dis.close();
                            } catch (IOException e) {
                                Log.e(TAG, "Unexpected IOException.", e);
                            } 
                        } 
                    } 
                } finally { 
                    if (entity != null) {

6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getContent, getContentLength
		} 
 
		HttpEntity entity = response.getEntity();
 
		ByteArrayOutputStream out =
			new ByteArrayOutputStream((int)entity.getContentLength());
		InputStream in = entity.getContent();
 
		try { 
			IOUtils.copyStream(in, out);
			return out.toByteArray();
		} finally { 
			IOUtils.closeQuietlyNullSafe(in);
		} 
	} 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getContentType
	protected <T> T doPost(String url, List<NameValuePair> params, ResponseHandler<T> responseHandler) {
		HttpPost request = new HttpPost(url);
		HttpEntity entity;
 
		try { 
			entity = new UrlEncodedFormEntity(params, "UTF-8");
		} 
		catch (UnsupportedEncodingException e) {
			Log.e("Couldn't encode params", e);
			return null; 
		} 
 
		Header header = entity.getContentType();
		if (header != null) {
			request.addHeader(header);
		} 
 
		request.setEntity(entity);
 
		Log.i("Request URL: " + url);
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android HttpEntity Questions & Answers:

Other Android HttpEntity Examples

7:	
8:				HttpResponse httpResponse = httpClient.execute(httpPost);
9:				HttpEntity httpEntity = httpResponse.getEntity();
10:				xml = EntityUtils.toString(httpEntity);
11:

Read More

48:	
49:					HttpResponse httpResponse = httpClient.execute(httpPost);
50:					HttpEntity httpEntity = httpResponse.getEntity();
51:					is = httpEntity.getContent();
52:	
-
59:	
60:					HttpResponse httpResponse = httpClient.execute(httpGet);
61:					HttpEntity httpEntity = httpResponse.getEntity();
62:					is = httpEntity.getContent();
63:				}

Read More

49:					HttpResponse httpResponse = httpClient.execute(httpPost);
50:					HttpEntity httpEntity = httpResponse.getEntity();
51:					is = httpEntity.getContent();
52:	
53:				}else if(method == "GET"){
-
60:					HttpResponse httpResponse = httpClient.execute(httpGet);
61:					HttpEntity httpEntity = httpResponse.getEntity();
62:					is = httpEntity.getContent();
63:				}			
64:

Read More

See Code Examples for Android HttpEntity Methods: