Merge branch 'close-feed-stream' into 'master'

Close InputStream from RSS feed and prevent NPE

See merge request !572
This commit is contained in:
akwizgran
2017-07-28 15:48:01 +00:00

View File

@@ -59,6 +59,7 @@ import okhttp3.Dns;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
@@ -334,7 +335,9 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
private SyndFeed fetchSyndFeed(String url) private SyndFeed fetchSyndFeed(String url)
throws FeedException, IOException { throws FeedException, IOException {
// fetch feed // fetch feed
SyndFeed f = getSyndFeed(getFeedInputStream(url)); InputStream stream = getFeedInputStream(url);
SyndFeed f = getSyndFeed(stream);
stream.close();
if (f.getEntries().size() == 0) if (f.getEntries().size() == 0)
throw new FeedException("Feed has no entries"); throw new FeedException("Feed has no entries");
@@ -387,7 +390,9 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
// Execute Request // Execute Request
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
return response.body().byteStream(); ResponseBody body = response.body();
if (body != null) return body.byteStream();
throw new IOException("Empty response body");
} }
private SyndFeed getSyndFeed(InputStream stream) private SyndFeed getSyndFeed(InputStream stream)