com.android.volley.toolbox.HttpHeaderParser Java Examples
The following examples show how to use
com.android.volley.toolbox.HttpHeaderParser.
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 File: Request4PushFreshComment.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@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 #2
Source File: GsonRequest.java From VolleyX with Apache License 2.0 | 6 votes |
@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
Source File: Request4FreshNewsDetail.java From JianDan with Apache License 2.0 | 6 votes |
@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 #4
Source File: Request4Picture.java From JianDan with Apache License 2.0 | 6 votes |
@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 #5
Source File: Request4Joke.java From JianDan with Apache License 2.0 | 6 votes |
@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
Source File: Request4PushFreshComment.java From JianDan with Apache License 2.0 | 6 votes |
@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 #7
Source File: Request4PushComment.java From JianDan_OkHttp with Apache License 2.0 | 6 votes |
@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 #8
Source File: Request4PushFreshComment.java From JianDan_OkHttp with Apache License 2.0 | 6 votes |
@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 File: Request4Joke.java From JianDan_OkHttp with Apache License 2.0 | 6 votes |
@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 File: Request4Picture.java From JianDan_OkHttp with Apache License 2.0 | 6 votes |
@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 #11
Source File: FileRequest.java From timelapse-sony with GNU General Public License v3.0 | 6 votes |
@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 #12
Source File: Request4Picture.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@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 #13
Source File: Request4FreshNewsDetail.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@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 #14
Source File: Request4Joke.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@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 File: AlbumRequest.java From meizhi with Apache License 2.0 | 6 votes |
@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 #16
Source File: Request4PushComment.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@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 #17
Source File: CatnutArrayRequest.java From catnut with MIT License | 6 votes |
@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 File: TransientUsersFragment.java From catnut with MIT License | 5 votes |
private Response<List<TransientUser>> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject result = new JSONObject(jsonString); // set next_cursor mNext_cursor = result.optInt(User.next_cursor); mTotal_number = result.optInt(User.total_number); JSONArray array = result.optJSONArray(User.MULTIPLE); if (array != null) { List<TransientUser> users = new ArrayList<TransientUser>(array.length()); for (int i = 0; i < array.length(); i++) { users.add(TransientUser.convert(array.optJSONObject(i))); } return Response.success(users, HttpHeaderParser.parseCacheHeaders(response)); } else { throw new RuntimeException("no users found!"); } } 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 ParseError(ex)); } }
Example #19
Source File: Request4CommentCounts.java From JianDan_OkHttp with Apache License 2.0 | 5 votes |
@Override protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response"); String[] comment_IDs = getUrl().split("\\=")[1].split("\\,"); ArrayList<CommentNumber> commentNumbers = new ArrayList<>(); for (String comment_ID : comment_IDs) { if (!jsonObject.isNull(comment_ID)) { CommentNumber commentNumber = new CommentNumber(); commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS)); commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID)); commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY)); commentNumbers.add(commentNumber); } else { //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据 commentNumbers.add(new CommentNumber("0", "0", 0)); } } return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example #20
Source File: VolleyNetworkStack.java From wasp with Apache License 2.0 | 5 votes |
@Override public void onErrorResponse(VolleyError error) { Response.Builder builder = new Response.Builder().setUrl(url); String errorMessage = null; if (error != null) { builder.setNetworkTime(error.getNetworkTimeMs()); errorMessage = error.getMessage(); if (error.networkResponse != null) { NetworkResponse response = error.networkResponse; String body; try { body = new String( error.networkResponse.data, HttpHeaderParser.parseCharset(response.headers) ); } catch (UnsupportedEncodingException e) { body = "Unable to parse error body!!!!!"; } builder.setStatusCode(response.statusCode) .setHeaders(response.headers) .setBody(body) .setLength(response.data.length); } } waspCallback.onError(new WaspError(builder.build(), errorMessage)); }
Example #21
Source File: InputStreamVolleyRequest.java From product-emm with Apache License 2.0 | 5 votes |
@Override protected Response<byte[]> parseNetworkResponse(NetworkResponse response) { //Initialise local responseHeaders map with response headers received responseHeaders = response.headers; //Pass the response data here return Response.success( response.data, HttpHeaderParser.parseCacheHeaders(response)); }
Example #22
Source File: InputStreamVolleyRequest.java From product-emm with Apache License 2.0 | 5 votes |
@Override protected Response<byte[]> parseNetworkResponse(NetworkResponse response) { //Initialise local responseHeaders map with response headers received responseHeaders = response.headers; //Pass the response data here return Response.success(response.data, HttpHeaderParser.parseCacheHeaders(response)); }
Example #23
Source File: GBKRequest.java From novel with Apache License 2.0 | 5 votes |
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, "GBK"); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); }
Example #24
Source File: MultipartRequest.java From android-common-utils with Apache License 2.0 | 5 votes |
@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 #25
Source File: Request4FreshNews.java From JianDan with Apache License 2.0 | 5 votes |
@Override protected Response<ArrayList<FreshNews>> parseNetworkResponse(NetworkResponse response) { try { String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject resultObj = new JSONObject(resultStr); JSONArray postsArray = resultObj.optJSONArray("posts"); return Response.success(FreshNews.parse(postsArray), HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example #26
Source File: Request4Vote.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
@Override protected Response<Vote> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(Vote.getInstance(jsonStr), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example #27
Source File: TSVRequest.java From conference-app with Apache License 2.0 | 5 votes |
@Override protected Response<List<Conference>> parseNetworkResponse(NetworkResponse response) { InputStream inputStream = new ByteArrayInputStream(response.data); List<Conference> conferences; try { conferences = Conference.parseInputStream(mContext, new InputStreamReader(inputStream)); } catch (Exception e) { mContext = null; return Response.error(new ParseError(e)); } return Response.success(conferences, HttpHeaderParser.parseCacheHeaders(response)); }
Example #28
Source File: StringRequestGet.java From renrenpay-android with Apache License 2.0 | 5 votes |
@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 #29
Source File: RequestRepos.java From CrossBow with Apache License 2.0 | 5 votes |
@Override protected Response<List<Repo>> parseNetworkResponse(NetworkResponse response) { Type type = new TypeToken<List<Repo>>(){}.getType(); JsonReader jsonReader = new JsonReader(new InputStreamReader(new ByteArrayInputStream(response.data))); List<Repo> repos = new Gson().fromJson(jsonReader, type); return Response.success(repos, HttpHeaderParser.parseCacheHeaders(response)); }
Example #30
Source File: GsonRequest.java From Rocko-Android-Demos with Apache License 2.0 | 5 votes |
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); if (mTypeToken == null) return Response.success(mGson.fromJson(jsonString, mClass), HttpHeaderParser.parseCacheHeaders(response)); else return (Response<T>) Response.success(mGson.fromJson(jsonString, mTypeToken.getType()), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } }