HttpEntity getContent - top ranked examples from Open Source projects

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

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();
7
CodeRank
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
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
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);
    } 
 
    /** 
6
CodeRank
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
This code example shows how to use the following methods:getContent
			HttpClient httpclient = new DefaultHttpClient();
			HttpGet httpget = new HttpGet(uri.toString());
			HttpResponse response = httpclient.execute(httpget);
			HttpEntity entity = response.getEntity();
			if (entity != null)
				return entity.getContent();
			else 
				throw new IOException("No HTTP response");
			// Use the regular java stuff 
			// URL url = new URL(uri.toString()); 
 
			// return url.openStream(); 
		} 
	} 
 
	/** 
	 * Get a stream that can be used for serialization 
	 *  
	 * @param context 
	 *            We'll write our data to this context private dir 
6
CodeRank
This code example shows how to use the following methods:getContent
 
        if( statusCode == HttpStatus.SC_OK )
        { 
            HttpEntity entity = response.getEntity();
 
            String body = CoreUtil.readStreamToString( entity.getContent() );
 
            EntityUtils.consume( entity );
 
            return body;
        } 
        else 
        { 
            return response.getStatusLine().getReasonPhrase();
        } 
    } 
 
    protected Object getJSONAPI( Object... args ) throws APIException
    { 
        if( !( args[0] instanceof String ) )
6
CodeRank
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);
		} 
	} 
} 
6
CodeRank
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;
					} 
				} 
6
CodeRank
This code example shows how to use the following methods:getContent

Related HttpEntity getContent Questions & Answers:

Other HttpEntity getContent Examples

76:				}
77:				httpEntity = httpResponse.getEntity();
78:				is = httpEntity.getContent();
79:	
80:			} catch (UnsupportedEncodingException e) {

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

50:					HttpEntity httpEntity = httpResponse.getEntity();
51:					is = httpEntity.getContent();
52:	
53:				}else if(method == "GET"){
54:					// request method is GET
-
61:					HttpEntity httpEntity = httpResponse.getEntity();
62:					is = httpEntity.getContent();
63:				}			
64:	
65:			} catch (UnsupportedEncodingException e) {

Read More

getContent Method Overview
Creates a new InputStream object of the entity.
See Code Examples for other Android HttpEntity Methods: