Back to project page Krautreporter.
The source code is released under:
MIT License
If you think the Android project Krautreporter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.metalmatze.krautreporter.helpers; /*from w ww .j a va 2 s . co m*/ import com.android.volley.NetworkResponse; import com.android.volley.ParseError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.toolbox.HttpHeaderParser; import org.xmlpull.v1.XmlPullParserException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; import de.metalmatze.krautreporter.KrautreporterRssParser; import de.metalmatze.krautreporter.models.ArticleModel; public class RssRequest extends Request<List<ArticleModel>> { private final Response.Listener<List<ArticleModel>> responseListener; public RssRequest(int method, String url, Response.Listener<List<ArticleModel>> responseListener, Response.ErrorListener errorListener) { super(method, url, errorListener); this.responseListener = responseListener; } @Override protected Response<List<ArticleModel>> parseNetworkResponse(NetworkResponse response) { List<ArticleModel> articles; try { InputStream inputStream = new ByteArrayInputStream(response.data); KrautreporterRssParser parser = new KrautreporterRssParser(); articles = parser.parse(inputStream); } catch (XmlPullParserException e) { return Response.error(new ParseError(e)); } catch (IOException e) { return Response.error(new ParseError(e)); } return Response.success(articles, HttpHeaderParser.parseCacheHeaders(response)); } @Override protected void deliverResponse(List<ArticleModel> response) { this.responseListener.onResponse(response); } }