Java Code Examples for com.android.volley.NetworkResponse

The following are top voted examples for showing how to use com.android.volley.NetworkResponse. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: ResponseTest.java   Source Code and License 7 votes vote down vote up
@Test
public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class));
    assertNotNull(Response.class.getMethod("error", VolleyError.class));
    assertNotNull(Response.class.getMethod("isSuccess"));

    assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class));

    assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse",
            VolleyError.class));

    assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
            boolean.class, long.class));
    assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
            boolean.class));
    assertNotNull(NetworkResponse.class.getConstructor(byte[].class));
    assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class));
}
 
Example 2
Project: GitHub   File: HttpHeaderParserTest.java   Source Code and License 6 votes vote down vote up
@Test public void parseCaseInsensitive() {

        long now = System.currentTimeMillis();

        Header[] headersArray = new Header[5];
        headersArray[0] = new BasicHeader("eTAG", "Yow!");
        headersArray[1] = new BasicHeader("DATE", rfc1123Date(now));
        headersArray[2] = new BasicHeader("expires", rfc1123Date(now + ONE_HOUR_MILLIS));
        headersArray[3] = new BasicHeader("cache-control", "public, max-age=86400");
        headersArray[4] = new BasicHeader("content-type", "text/plain");

        Map<String, String> headers = BasicNetwork.convertHeaders(headersArray);
        NetworkResponse response = new NetworkResponse(0, null, headers, false);
        Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

        assertNotNull(entry);
        assertEquals("Yow!", entry.etag);
        assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
        assertEquals(entry.softTtl, entry.ttl);
        assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
    }
 
Example 3
Project: GitHub   File: ResponseTest.java   Source Code and License 6 votes vote down vote up
@Test
public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class));
    assertNotNull(Response.class.getMethod("error", VolleyError.class));
    assertNotNull(Response.class.getMethod("isSuccess"));

    assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class));

    assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse",
            VolleyError.class));

    assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
            boolean.class, long.class));
    assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
            boolean.class));
    assertNotNull(NetworkResponse.class.getConstructor(byte[].class));
    assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class));
}
 
Example 4
Project: super-volley   File: BaseRequest.java   Source Code and License 6 votes vote down vote up
@Override
protected com.android.volley.Response<String> parseNetworkResponse(NetworkResponse response) {
    this.statusCode = response.statusCode;
    this.responseHeaders = response.headers;
    /* Get the response data */
    try {
        String json = "";
        if (response.data != null) {
            json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        }
        String log = "%1$s\nResponse code: %2$s\nResponse body: %3$s";
        VolleyLog.v(log, getUrl(), statusCode, json);
        if (statusCode >= 200 && statusCode < 300) {
            /* Return the parsed result in a response wrapper */
            return shouldCache() ?
                    success(json, parseIgnoreCacheHeaders(response)) :
                    success(json, parseCacheHeaders(response));
        } else {
            return error(new ServerError(response));
        }
    } catch (UnsupportedEncodingException e) {
        return error(new ParseError(e));
    }
}
 
Example 5
Project: plainrequest   File: RequestCustom.java   Source Code and License 6 votes vote down vote up
/**
 * Retorna o Response conforme seu tipo
 *
 * @param response
 * @return
 * @throws UnsupportedEncodingException
 * @throws JSONException
 */
private Response getResponse(NetworkResponse response) throws UnsupportedEncodingException, JSONException {
    T result;

    byte[] data = response.data;

    if (isResponseCompressed(response)) {
        data = gzipToByte(data);
    }

    if (superClass.equals(JSONObject.class)) {
        result = (T) new JSONObject(convertData(data));
    } else if (superClass.equals(JSONArray.class)) {
        result = (T) new JSONArray(convertData(data));
    } else {
        result = (T) convertData(data);
    }

    return Response.success(result, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 6
Project: Codeforces   File: ResponseTest.java   Source Code and License 6 votes vote down vote up
@Test
public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class));
    assertNotNull(Response.class.getMethod("error", VolleyError.class));
    assertNotNull(Response.class.getMethod("isSuccess"));

    assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class));

    assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse",
            VolleyError.class));

    assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
            boolean.class, long.class));
    assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
            boolean.class));
    assertNotNull(NetworkResponse.class.getConstructor(byte[].class));
    assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class));
}
 
Example 7
Project: RestClient   File: RestRequest.java   Source Code and License 6 votes vote down vote up
@Override
protected Response<RemoteResponse> parseNetworkResponse(NetworkResponse response) {
    RemoteResponse remoteResponse = new RemoteResponse();
    if (null != response) {
        try {
            remoteResponse.setStatusCode(response.statusCode);
            remoteResponse.setResponseMessage(HttpStatusNoteMap.getNote(response.statusCode));
            remoteResponse.setInterval(response.networkTimeMs);
            remoteResponse.setHeaders(response.headers);
            String str = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
            remoteResponse.setResponse(str);

        } catch (UnsupportedEncodingException e) {
            remoteResponse.setResponse(e.getMessage());
        }
    } else {
        remoteResponse.setStatusCode(-1);
        remoteResponse.setResponseMessage("Error");
    }
    return Response.success(remoteResponse, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 8
Project: GitHub   File: JsonObjectRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(new JSONObject(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 9
Project: GitHub   File: ImageRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example 10
Project: swaggy-jenkins   File: PostRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
  String parsed;
  try {
    parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
  } catch (UnsupportedEncodingException e) {
    parsed = new String(response.data);
  }
  return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 11
Project: boohee_v5.6   File: BaseJsonRequest.java   Source Code and License 5 votes vote down vote up
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    if (response == null) {
        return null;
    }
    String parsed;
    try {
        parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
    } catch (Exception e) {
        parsed = new String(response.data);
    }
    return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 12
Project: iosched-reader   File: JsonArrayRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString =
            new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        return Response.success(new JSONArray(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 13
Project: stitch-android-sdk   File: Volley.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(final NetworkResponse response) {
    try {
        return Response.success(
                new String(
                        response.data,
                        HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    }
}
 
Example 14
Project: plainrequest   File: RequestCustom.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        this.statusCode = response.statusCode;
        return getResponse(response);
    } catch (UnsupportedEncodingException e1) {
        return Response.error(new ParseError(e1));
    } catch (JSONException e2) {
        return Response.error(new ParseError(e2));
    }
}
 
Example 15
Project: GitHub   File: JsonRequestCharsetTest.java   Source Code and License 5 votes vote down vote up
@Test public void defaultCharsetJsonArray() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
 
Example 16
Project: boohee_v5.6   File: StringRequest.java   Source Code and License 5 votes vote down vote up
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    String parsed;
    try {
        parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
    } catch (UnsupportedEncodingException e) {
        parsed = new String(response.data);
    }
    return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 17
Project: GitHub   File: JsonRequestCharsetTest.java   Source Code and License 5 votes vote down vote up
@Test public void specifiedCharsetJsonArray() throws Exception {
    byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-2");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    // don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
 
Example 18
Project: GitHub   File: ImageRequestTest.java   Source Code and License 5 votes vote down vote up
private void verifyResize(NetworkResponse networkResponse, int maxWidth, int maxHeight,
                          ScaleType scaleType, int expectedWidth, int expectedHeight) {
    ImageRequest request = new ImageRequest("", null, maxWidth, maxHeight, scaleType,
            Config.RGB_565, null);
    Response<Bitmap> response = request.parseNetworkResponse(networkResponse);
    assertNotNull(response);
    assertTrue(response.isSuccess());
    Bitmap bitmap = response.result;
    assertNotNull(bitmap);
    assertEquals(expectedWidth, bitmap.getWidth());
    assertEquals(expectedHeight, bitmap.getHeight());
}
 
Example 19
Project: GitHub   File: JsonObjectRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(new JSONObject(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 20
Project: GeekZone   File: JsonArrayRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(new JSONArray(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 21
Project: GitHub   File: ImageRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example 22
Project: GitHub   File: StringRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    String parsed;
    try {
        parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
    } catch (UnsupportedEncodingException e) {
        parsed = new String(response.data);
    }
    return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 23
Project: Saiy-PS   File: BingTranslateAPI.java   Source Code and License 5 votes vote down vote up
/**
 * Used for debugging only to view verbose error information
 *
 * @param error the {@link VolleyError}
 */
private void verboseError(@NonNull final VolleyError error) {

    final NetworkResponse response = error.networkResponse;

    if (response != null && error instanceof ServerError) {

        try {
            final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
            MyLog.i(CLS_NAME, "result: " + result);
        } catch (final UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
 
Example 24
Project: GitHub   File: MockNetwork.java   Source Code and License 5 votes vote down vote up
@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    if (mNumExceptionsToThrow > 0 || mNumExceptionsToThrow == ALWAYS_THROW_EXCEPTIONS) {
        if (mNumExceptionsToThrow != ALWAYS_THROW_EXCEPTIONS) {
            mNumExceptionsToThrow--;
        }
        throw new ServerError();
    }

    requestHandled = request;
    return new NetworkResponse(mDataToReturn);
}
 
Example 25
Project: GitHub   File: JsonRequestCharsetTest.java   Source Code and License 5 votes vote down vote up
@Test public void defaultCharsetJsonObject() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonObjectString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
    Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);

    assertNotNull(objectResponse);
    assertTrue(objectResponse.isSuccess());
    assertEquals(TEXT_VALUE, objectResponse.result.getString(TEXT_NAME));
    assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
 
Example 26
Project: GitHub   File: JsonRequestCharsetTest.java   Source Code and License 5 votes vote down vote up
@Test public void specifiedCharsetJsonObject() throws Exception {
    byte[] data = jsonObjectString().getBytes(Charset.forName("ISO-8859-1"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-1");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
    Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);

    assertNotNull(objectResponse);
    assertTrue(objectResponse.isSuccess());
    //don't check the text in Czech, ISO-8859-1 doesn't support some Czech characters
    assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
 
Example 27
Project: Saiy-PS   File: ListIDProfiles.java   Source Code and License 5 votes vote down vote up
/**
 * Used for debugging only to view verbose error information
 *
 * @param error the {@link VolleyError}
 */
private void verboseError(@NonNull final VolleyError error) {

    final NetworkResponse response = error.networkResponse;

    if (response != null && error instanceof ServerError) {

        try {
            final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
            MyLog.i(CLS_NAME, "result: " + result);
        } catch (final UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
 
Example 28
Project: publicProject   File: JRYGRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    // TODO Auto-generated method stub
    try {
        CommonLog.d("请求成功:statusCode:" + response.statusCode);
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        CommonLog.d(url + "返回:" + jsonStr);
        return Response.success(JSON.parseObject(jsonStr, mClazz), HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        CommonLog.d("请求失败!");
        return Response.error(new ParseError(e));
    }
}
 
Example 29
Project: publicProject   File: JsonObjectRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(new JSONObject(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 30
Project: iosched-reader   File: MockNetwork.java   Source Code and License 5 votes vote down vote up
@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    if (mNumExceptionsToThrow > 0 || mNumExceptionsToThrow == ALWAYS_THROW_EXCEPTIONS) {
        if (mNumExceptionsToThrow != ALWAYS_THROW_EXCEPTIONS) {
            mNumExceptionsToThrow--;
        }
        throw new ServerError();
    }

    requestHandled = request;
    return new NetworkResponse(mDataToReturn);
}
 
Example 31
Project: publicProject   File: ImageRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example 32
Project: publicProject   File: StringRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    String parsed;
    try {
        parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
    } catch (UnsupportedEncodingException e) {
        parsed = new String(response.data);
    }
    return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 33
Project: boohee_v5.6   File: ImageRequest.java   Source Code and License 5 votes vote down vote up
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    Response<Bitmap> doParse;
    synchronized (sDecodeLock) {
        try {
            doParse = doParse(response);
        } catch (Throwable e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", Integer.valueOf(response.data.length), getUrl());
            doParse = Response.error(new ParseError(e));
        }
    }
    return doParse;
}
 
Example 34
Project: ez-volley   File: VolleyRequest.java   Source Code and License 5 votes vote down vote up
/**
 * DELETE string request.
 *
 * @param url      URL for post API request
 * @param listener Listener
 */
public static void deleteRequest(String url, final VolleyResponseListener listener) {
    StringRequest stringRequest = new StringRequest(Request.Method.DELETE, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            listener.onResponse(s);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            if (volleyError != null) {
                listener.onError(volleyError);
            }
        }
    }) {
        @Override
        protected Response<String> parseNetworkResponse(NetworkResponse response) {
            listener.onNetworkResponse(response);
            return super.parseNetworkResponse(response);
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Accept", "application/json");
            params.put("Content-Type", "application/json; charset=UTF-8");
            params.put("Cache-Control", "no-cache");
            params.put("Authorization", "");
            return params;
        }

        @Override
        public Priority getPriority() {
            return Priority.IMMEDIATE;
        }
    };

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    VolleySingleton.getInstance().getRequestQueue().add(stringRequest);
}
 
Example 35
Project: iosched-reader   File: ImageRequestTest.java   Source Code and License 5 votes vote down vote up
private void verifyResize(NetworkResponse networkResponse, int maxWidth, int maxHeight,
        int expectedWidth, int expectedHeight) {
    ImageRequest request = new ImageRequest(
            "", null, maxWidth, maxHeight, Config.RGB_565, null);
    Response<Bitmap> response = request.parseNetworkResponse(networkResponse);
    assertNotNull(response);
    assertTrue(response.isSuccess());
    Bitmap bitmap = response.result;
    assertNotNull(bitmap);
    assertEquals(expectedWidth, bitmap.getWidth());
    assertEquals(expectedHeight, bitmap.getHeight());
}
 
Example 36
Project: payments-Android-SDK   File: PostRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
  String parsed;
  try {
    parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
  } catch (UnsupportedEncodingException e) {
    parsed = new String(response.data);
  }
  return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 37
Project: payments-Android-SDK   File: DeleteRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
  String parsed;
    try {
      parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
    } catch (UnsupportedEncodingException e) {
      parsed = new String(response.data);
    }
  return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 38
Project: payments-Android-SDK   File: PatchRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
  String parsed;
  try {
    parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
  } catch (UnsupportedEncodingException e) {
    parsed = new String(response.data);
  }
  return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
 
Example 39
Project: TYT   File: JsonObjectPostRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 40
Project: AndroidCrossPromotion   File: CustomRequest.java   Source Code and License 5 votes vote down vote up
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers));
        return Response.success(new JSONObject(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}