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


Java HttpHeaderParser類代碼示例

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


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

示例1: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的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

示例2: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的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

示例3: doParse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
/**
 * The real guts of parseNetworkResponse. Broken out for readability.
 */
private Response<Bitmap> doParse(NetworkResponse response) {
    byte[] data = response.data;
    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    Bitmap bitmap = null;
    if (mMaxWidth == 0 && mMaxHeight == 0) {
        if (mDecodeConfig != null) {
            decodeOptions.inPreferredConfig = mDecodeConfig;
        }
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
    } else {
        bitmap = ImageUtils.compressBitmap(data, mMaxWidth, mMaxHeight);
    }

    if (bitmap == null) {
        return Response.error(new ParseError());
    } else {
        return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
    }
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:23,代碼來源:BaseImageRequest.java

示例4: getResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的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.toolbox.HttpHeaderParser; //導入依賴的package包/類
/**
 * 通信結束後返回的回調方法.
 *
 * @param networkResponse 返回的響應結果對象
 */
@Override
protected Response<CommonResponse> parseNetworkResponse(NetworkResponse networkResponse) {
    CommonResponse response = new CommonResponse();
    // 獲得字符串返回結果
    String jsonString;
    try {
        App.getInstance().setCookie(networkResponse.headers.get(SET_COOKIE_KEY));
        jsonString = new String(networkResponse.data, HttpHeaderParser.parseCharset(networkResponse.headers, OpenApi.CHARSET_UTF8));
        Logger.i(jsonString);
        // 轉換返回結果為指定對象
        this.doParse(jsonString, mFormat, mTypeToken, response, mRawData);
    } catch (UnsupportedEncodingException e) {
        response.setCodeEnum(CodeEnum.DATA_PARSE_ERROR);
    }
    return Response.success(response, HttpHeaderParser.parseCacheHeaders(networkResponse));
}
 
開發者ID:tengbinlive,項目名稱:ooooim_android,代碼行數:22,代碼來源:CommonRequest.java

示例6: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的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:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:18,代碼來源:BaseArrayJsonRequest.java

示例7: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString = new String(response.data,
				HttpHeaderParser.parseCharset(response.headers));
		//Allow null
		if (jsonString == null || jsonString.length() == 0)
		{
			return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
		}
		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:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:23,代碼來源:BaseJsonRequest.java

示例8: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的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:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:18,代碼來源:BaseMultipartJsonRequest.java

示例9: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
@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));
	}
}
 
開發者ID:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:18,代碼來源:BaseMultipartJsonArrayRequest.java

示例10: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
@Override
public Response<T> parseNetworkResponse(NetworkResponse response) {

    String parsed;
    try {

        String charsetName = HttpHeaderParser.parseCharset(response.headers);
        parsed = new String(response.data, charsetName);
    } catch (UnsupportedEncodingException e) {

        parsed = new String(response.data);
        e.printStackTrace();
    }

    QyerResponse<T> resp = onResponse(parsed);
    if (resp.isSuccess()) {

        Entry entry = HttpHeaderParser.parseCacheHeaders(response);
        mObjResp = Response.success(resp.getData(), entry);
        return mObjResp;
    } else {

        return Response.error(new VolleyError(resp.getMsg()));
    }
}
 
開發者ID:joy-inc,項目名稱:joy-library,代碼行數:26,代碼來源:ObjectRequest.java

示例11: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    if (mType == null && mJavaClass == null) return Response.error(new ParseError());
    try {
        String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        T parsedGSON = null;
        if (mType != null) {
            parsedGSON = mGson.fromJson(jsonString, mType);
        } else {
            parsedGSON = mGson.fromJson(jsonString, mJavaClass);
        }
        return Response.success(parsedGSON,
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JsonSyntaxException je) {
        return Response.error(new ParseError(je));
    }
}
 
開發者ID:yangweigbh,項目名稱:VolleyX,代碼行數:20,代碼來源:GsonRequest.java

示例12: cache

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
/**
 * 強製緩存
 * @param response 接收體
 * @param maxAge 緩存時間
 */
private static Cache.Entry cache(NetworkResponse response, long maxAge) {
    long now = System.currentTimeMillis();
    if (maxAge == 0)
        maxAge = 60;
    Map<String, String> headers = response.headers;

    long serverDate = 0;
    long softExpire = 0;
    String serverEtag = null;
    String headerValue;

    headerValue = headers.get("Date");
    if (headerValue != null) {
        serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
    }
    softExpire = now + maxAge * 1000;
    Cache.Entry entry = new Cache.Entry();
    entry.data = response.data;
    entry.etag = serverEtag;
    entry.softTtl = softExpire;
    entry.ttl = entry.softTtl;
    entry.serverDate = serverDate;
    entry.responseHeaders = headers;
    return entry;
}
 
開發者ID:Temoa,項目名稱:Startor,代碼行數:31,代碼來源:GsonRequest.java

示例13: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
/**
     * 數據返回
     */
    @Override
    protected Response<T> parseNetworkResponse(NetworkResponse response) {
        try {
            String strRue = new String(response.data, "UTF-8");
//            if (BuildConfig.DEBUG)
//                Log.d(TAG, xml);
            if (strRue.contains("error")) { //server返回錯誤
                ServerErrorResult serverError = mGson.fromJson(strRue,ServerErrorResult.class);
                Response.error(new MyErrorMessage(serverError.getStatus(),serverError.getMessage()));
            }
            return Response.success(mGson.fromJson(strRue,mClazz),HttpHeaderParser.parseCacheHeaders(response));
        } catch (Exception e) {
            e.printStackTrace();
            return Response.error(new ParseError(e));
        }
    }
 
開發者ID:yun2win,項目名稱:yun2win-sdk-android,代碼行數:20,代碼來源:MyRequest.java

示例14: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {

    try {
        Map<String, String> headers = response.headers;
        // TODO: 16/6/1 可以處理網絡返回頭信息

        String parsed = "";
        if (response.data != null && response.data.length > 0) {
            parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
        }
        T map = gson.fromJson(parsed,
                new TypeToken<T>() {
                }.getType());

        return Response.success(map, HttpHeaderParser.parseCacheHeaders(response));
    } catch (Exception je) {
        return Response.error(new ParseError(je));
    }

}
 
開發者ID:jessie345,項目名稱:RealArchitecture,代碼行數:22,代碼來源:VolleyRequest.java

示例15: parseNetworkResponse

import com.android.volley.toolbox.HttpHeaderParser; //導入依賴的package包/類
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {

	try {
		String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response
				.headers));
		JSONObject jsonObject = new JSONObject(resultStr);

		if (jsonObject.opt("status").equals("ok")) {
			JSONObject contentObject = jsonObject.optJSONObject("post");
			return Response.success(contentObject.optString("content"), HttpHeaderParser.parseCacheHeaders
					(response));
		} else {
			return Response.success("error", HttpHeaderParser.parseCacheHeaders(response));
		}

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
開發者ID:niuzehai,項目名稱:Sxumiro_AndroidClient,代碼行數:22,代碼來源:Request4FreshNewsDetail.java


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