Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java

Issue 29453722: Noissue - Lint adjustments and optimizations (Closed)
Patch Set: Created June 1, 2017, 9:30 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java
===================================================================
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java
@@ -26,30 +26,29 @@ import java.nio.charset.StandardCharsets
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import android.annotation.SuppressLint;
-import android.content.Context;
import android.util.Log;
@SuppressLint("DefaultLocale")
final class Downloader
{
private static final int MAX_RETRIES = 5;
private static final String TAG = Downloader.class.getSimpleName();
private final Engine engine;
private final ReentrantLock accessLock = new ReentrantLock();
private Thread downloaderThread;
- private LinkedBlockingQueue<DownloadJob> downloadJobs = new LinkedBlockingQueue<>();
- private HashSet<String> enqueuedIds = new HashSet<>();
+ private final LinkedBlockingQueue<DownloadJob> downloadJobs = new LinkedBlockingQueue<>();
+ private final HashSet<String> enqueuedIds = new HashSet<>();
private boolean downloaderEnabled = true;
private Downloader(final Engine engine)
{
this.engine = engine;
}
void lock()
@@ -72,22 +71,19 @@ final class Downloader
this.downloaderEnabled = true;
this.unlock();
}
static void download(final DownloadJob job) throws IOException
{
final HttpURLConnection connection = (HttpURLConnection) job.url.openConnection();
connection.setRequestMethod("GET");
- if (job.headers != null)
+ for (final Entry<String, String> e : job.headers.entrySet())
{
- for (final Entry<String, String> e : job.headers.entrySet())
- {
- connection.addRequestProperty(e.getKey(), e.getValue());
- }
+ connection.addRequestProperty(e.getKey(), e.getValue());
}
connection.connect();
job.responseCode = connection.getResponseCode();
job.responseHeaders.clear();
job.responseText = null;
for (int i = 1;; i++)
@@ -125,17 +121,17 @@ final class Downloader
}
}
finally
{
this.unlock();
}
}
- public static Downloader create(final Context context, final Engine engine)
+ public static Downloader create(final Engine engine)
{
final Downloader downloader = new Downloader(engine);
downloader.downloaderThread = new Thread(new DownloaderHandler(downloader));
downloader.downloaderThread.setDaemon(true);
downloader.downloaderThread.start();
return downloader;
@@ -244,17 +240,17 @@ final class Downloader
private static class DownloadJob
{
private final URL url;
private final String id;
private final HashMap<String, String> headers = new HashMap<>();
private int retryCount = 0;
private int responseCode = 0;
- private HashMap<String, String> responseHeaders = new HashMap<>();
+ private final HashMap<String, String> responseHeaders = new HashMap<>();
private String responseText = null;
public DownloadJob(final URL url, final String id, final Map<String, String> headers)
{
this.url = url;
this.id = id;
if (headers != null)
{

Powered by Google App Engine
This is Rietveld