當前位置: 首頁>>代碼示例>>Java>>正文


Java NetworkResponse類代碼示例

本文整理匯總了Java中com.android.volley.NetworkResponse的典型用法代碼示例。如果您正苦於以下問題:Java NetworkResponse類的具體用法?Java NetworkResponse怎麽用?Java NetworkResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NetworkResponse類屬於com.android.volley包,在下文中一共展示了NetworkResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: publicMethods

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ResponseTest.java

示例2: parseCaseInsensitive

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:HttpHeaderParserTest.java

示例3: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:octaware,項目名稱:super-volley,代碼行數:25,代碼來源:BaseRequest.java

示例4: getResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
/**
 * 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));
}
 
開發者ID:giovanimoura,項目名稱:plainrequest,代碼行數:28,代碼來源:RequestCustom.java

示例5: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
}
 
開發者ID:Sayi,項目名稱:RestClient,代碼行數:22,代碼來源:RestRequest.java

示例6: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:JsonObjectRequest.java

示例7: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:ImageRequest.java

示例8: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
}
 
開發者ID:cliffano,項目名稱:swaggy-jenkins,代碼行數:11,代碼來源:PostRequest.java

示例9: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
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));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:13,代碼來源:BaseJsonRequest.java

示例10: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:14,代碼來源:JsonArrayRequest.java

示例11: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:mongodb,項目名稱:stitch-android-sdk,代碼行數:13,代碼來源:Volley.java

示例12: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:giovanimoura,項目名稱:plainrequest,代碼行數:12,代碼來源:RequestCustom.java

示例13: defaultCharsetJsonArray

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:JsonRequestCharsetTest.java

示例14: parseNetworkResponse

import com.android.volley.NetworkResponse; //導入依賴的package包/類
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));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:10,代碼來源:StringRequest.java

示例15: specifiedCharsetJsonArray

import com.android.volley.NetworkResponse; //導入依賴的package包/類
@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
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:JsonRequestCharsetTest.java


注:本文中的com.android.volley.NetworkResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。