Search in sources :

Example 16 with ServerError

use of com.android.volley.ServerError in project saga-android by AnandChowdhary.

the class BasicNetwork method entityToBytes.

/** Reads the contents of HttpEntity into a byte[]. */
private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
    byte[] buffer = null;
    try {
        InputStream in = entity.getContent();
        if (in == null) {
            throw new ServerError();
        }
        buffer = mPool.getBuf(1024);
        int count;
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            entity.consumeContent();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        mPool.returnBuf(buffer);
        bytes.close();
    }
}
Also used : InputStream(java.io.InputStream) ServerError(com.android.volley.ServerError) IOException(java.io.IOException)

Aggregations

ServerError (com.android.volley.ServerError)16 IOException (java.io.IOException)15 AuthFailureError (com.android.volley.AuthFailureError)8 NetworkError (com.android.volley.NetworkError)8 NetworkResponse (com.android.volley.NetworkResponse)8 NoConnectionError (com.android.volley.NoConnectionError)8 TimeoutError (com.android.volley.TimeoutError)8 MalformedURLException (java.net.MalformedURLException)8 SocketTimeoutException (java.net.SocketTimeoutException)8 HashMap (java.util.HashMap)8 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)8 InputStream (java.io.InputStream)7 HttpResponse (org.apache.http.HttpResponse)7 StatusLine (org.apache.http.StatusLine)7 Entry (com.android.volley.Cache.Entry)4 Cache (com.android.volley.Cache)1 ClientError (com.android.volley.ClientError)1 RedirectError (com.android.volley.RedirectError)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1