Java Code Examples for com.android.volley.toolbox.HttpHeaderParser

The following examples show how to use com.android.volley.toolbox.HttpHeaderParser. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: timelapse-sony   Source File: FileRequest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {

    try {
        BufferedOutputStream bos = new BufferedOutputStream(
                new FileOutputStream(mOutputFile));
        bos.write(response.data);
        bos.flush();
        bos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));

}
 
Example 2
Source Project: VolleyX   Source File: GsonRequest.java    License: Apache License 2.0 6 votes vote down vote up
@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));
    }
}
 
Example 3
@Override
protected Response<Boolean> parseNetworkResponse(NetworkResponse response) {

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

        JSONObject resultObj = new JSONObject(resultStr);
        int code = resultObj.optInt("code");
        if (code == 0) {
            return Response.success(true, HttpHeaderParser.parseCacheHeaders(response));
        } else {
            return Response.error(new VolleyError("错误码:" + code));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new VolleyError(e));
    }

}
 
Example 4
@Override
protected Response<Boolean> parseNetworkResponse(NetworkResponse response) {

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

		JSONObject resultObj = new JSONObject(resultStr);
		String result = resultObj.optString("status");
		String error=resultObj.optString("error");
		if ( result.equals("ok")) {
			return Response.success(true, HttpHeaderParser.parseCacheHeaders(response));
		} else {
			return Response.error(new VolleyError("错误原因:" + error));
		}
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new VolleyError(e));
	}

}
 
Example 5
Source Project: JianDan_OkHttpWithVolley   Source File: Request4Joke.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Joke>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		return Response.success((ArrayList<Joke>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Joke>>() {
				}.getType()), HttpHeaderParser.parseCacheHeaders(response));

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 6
@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));
	}
}
 
Example 7
Source Project: JianDan_OkHttpWithVolley   Source File: Request4Picture.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 8
Source Project: JianDan   Source File: Request4PushFreshComment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<Boolean> parseNetworkResponse(NetworkResponse response) {

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

		JSONObject resultObj = new JSONObject(resultStr);
		String result = resultObj.optString("status");
		String error=resultObj.optString("error");
		if ( result.equals("ok")) {
			return Response.success(true, HttpHeaderParser.parseCacheHeaders(response));
		} else {
			return Response.error(new VolleyError("错误原因:" + error));
		}
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new VolleyError(e));
	}

}
 
Example 9
Source Project: JianDan   Source File: Request4Joke.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Joke>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		return Response.success((ArrayList<Joke>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Joke>>() {
				}.getType()), HttpHeaderParser.parseCacheHeaders(response));

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 10
Source Project: JianDan   Source File: Request4FreshNewsDetail.java    License: Apache License 2.0 6 votes vote down vote up
@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));
	}
}
 
Example 11
Source Project: JianDan   Source File: Request4Picture.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 12
Source Project: JianDan_OkHttp   Source File: Request4PushComment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<Boolean> parseNetworkResponse(NetworkResponse response) {

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

        JSONObject resultObj = new JSONObject(resultStr);
        int code = resultObj.optInt("code");
        if (code == 0) {
            return Response.success(true, HttpHeaderParser.parseCacheHeaders(response));
        } else {
            return Response.error(new VolleyError("错误码:" + code));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new VolleyError(e));
    }

}
 
Example 13
Source Project: JianDan_OkHttp   Source File: Request4PushFreshComment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<Boolean> parseNetworkResponse(NetworkResponse response) {

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

        JSONObject resultObj = new JSONObject(resultStr);
        String result = resultObj.optString("status");
        String error = resultObj.optString("error");
        if (result.equals("ok")) {
            return Response.success(true, HttpHeaderParser.parseCacheHeaders(response));
        } else {
            return Response.error(new VolleyError("错误原因:" + error));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new VolleyError(e));
    }

}
 
Example 14
Source Project: JianDan_OkHttp   Source File: Request4Joke.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Joke>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		return Response.success((ArrayList<Joke>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Joke>>() {
				}.getType()), HttpHeaderParser.parseCacheHeaders(response));

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 15
Source Project: JianDan_OkHttp   Source File: Request4Picture.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 16
Source Project: meizhi   Source File: AlbumRequest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<List<Image>> parseNetworkResponse(NetworkResponse response) {
    try {
        List<Image> images = new ArrayList<>();

        Document document = Jsoup.parse(new String(response.data,
                HttpHeaderParser.parseCharset(response.headers)));

        for (Element img : document.select(".container.main .box.show-box img")) {
            String url = img.attr("src");
            if (TextUtils.isEmpty(url)) {
                continue;
            }

            Image image = new Image();
            image.url = url;

            images.add(image);
        }

        return Response.success(images, HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    }
}
 
Example 17
Source Project: catnut   Source File: CatnutArrayRequest.java    License: MIT License 6 votes vote down vote up
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
	try {
		String jsonString =
				new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		Response<JSONArray> success = Response.success(new JSONArray(jsonString),
				HttpHeaderParser.parseCacheHeaders(response));
		if (mProcessor != null) {
			// do in background...
			mProcessor.asyncProcess(mContext, success.result);
		}
		return success;
	} catch (UnsupportedEncodingException e) {
		return Response.error(new ParseError(e));
	} catch (JSONException je) {
		return Response.error(new ParseError(je));
	} catch (Exception ex) {
		return Response.error(new VolleyError(ex));
	}
}
 
Example 18
Source Project: renrenpay-android   Source File: StringRequestGet.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(jsonString, HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 19
@Override
protected Response<NetworkResponse> parseNetworkResponse(NetworkResponse response) {
    try {
        return Response.success(
                response,
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (Exception e) {
        return Response.error(new ParseError(e));
    }
}
 
Example 20
Source Project: openapi-generator   Source File: PostRequest.java    License: Apache License 2.0 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 21
Source Project: openapi-generator   Source File: PutRequest.java    License: Apache License 2.0 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 22
Source Project: openapi-generator   Source File: DeleteRequest.java    License: Apache License 2.0 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
Source Project: openapi-generator   Source File: PatchRequest.java    License: Apache License 2.0 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 24
Source Project: Tpay   Source File: StringRequestGet.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(jsonString, HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 25
Source Project: Tpay   Source File: FastJsonRequest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Response<BaseMsg> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(
                JSON.parseObject(jsonString, BaseMsg.class), HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example 26
Source Project: Saiy-PS   Source File: BVAuthRequest.java    License: GNU Affero General Public License v3.0 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 27
/**
 * 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
/**
 * 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 29
/**
 * 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 30
/**
 * 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();
        }
    }
}