当前位置: 首页>>代码示例>>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;未经允许,请勿转载。