Search in sources :

Example 26 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project CodeUtils by boredream.

the class BmobHttpUtils method entityFromConnection.

/**
	 * Initializes an {@link HttpEntity} from the given
	 * {@link HttpURLConnection}.
	 * 
	 * @param connection
	 * @return an HttpEntity populated with data from <code>connection</code>.
	 */
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
    BasicHttpEntity entity = new BasicHttpEntity();
    InputStream inputStream;
    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;
}
Also used : InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) IOException(java.io.IOException)

Aggregations

BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)26 InputStream (java.io.InputStream)12 IOException (java.io.IOException)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ChunkedInputStream (org.apache.http.impl.io.ChunkedInputStream)6 ContentLengthInputStream (org.apache.http.impl.io.ContentLengthInputStream)6 IdentityInputStream (org.apache.http.impl.io.IdentityInputStream)6 Test (org.junit.Test)4 FetchProfile (com.fsck.k9.mail.FetchProfile)3 Header (org.apache.http.Header)3 HttpResponse (org.apache.http.HttpResponse)3 StatusLine (org.apache.http.StatusLine)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 HttpContext (org.apache.http.protocol.HttpContext)3 Matchers.anyString (org.mockito.Matchers.anyString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 HttpEntity (org.apache.http.HttpEntity)2 HttpException (org.apache.http.HttpException)2 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)2 AccountLimitException (com.cloud.exception.AccountLimitException)1