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

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

Issue 29453722: Noissue - Lint adjustments and optimizations (Closed)
Patch Set: Adjustments based on review comments Created June 13, 2017, 9:23 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/Subscription.java
===================================================================
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Subscription.java
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Subscription.java
@@ -39,16 +39,17 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import android.text.TextUtils;
+import android.text.format.DateUtils;
import android.util.Log;
/**
* Simple subscription representation.
*/
final class Subscription
{
private static final String TAG = Subscription.class.getSimpleName();
@@ -59,24 +60,24 @@ final class Subscription
public static final String KEY_HTTP_LAST_MODIFIED = "_last_modified";
public static final String KEY_UPDATE_TIMESTAMP = "_update_timestamp";
public static final String KEY_TRIED_UPDATE_TIMESTAMP = "_tried_update_timestamp";
public static final String KEY_DOWNLOAD_COUNT = "_download_count";
public static final String KEY_ENABLED = "_enabled";
public static final String KEY_HAS_FILTERS = "_has_filters";
public static final String KEY_META_HASH = "_meta_hash";
- public static final long MINIMAL_DOWNLOAD_INTERVAL = Engine.MILLIS_PER_HOUR / 4;
- public static final long DOWNLOAD_RETRY_INTERVAL = Engine.MILLIS_PER_HOUR;
+ private static final long MINIMAL_DOWNLOAD_INTERVAL = DateUtils.HOUR_IN_MILLIS / 4;
+ private static final long DOWNLOAD_RETRY_INTERVAL = DateUtils.HOUR_IN_MILLIS;
private static final HashSet<String> ALLOWED_META_KEYS = new HashSet<>();
private static final Locale LOCALE_EN = Locale.ENGLISH;
- private final long updateInterval = Engine.MILLIS_PER_DAY
- + (long) (Engine.MILLIS_PER_HOUR * 8. * Math.random());
+ private final long updateInterval = DateUtils.DAY_IN_MILLIS
+ + (long) (DateUtils.HOUR_IN_MILLIS * 8. * Math.random());
/**
* List of meta keys that are allowed to import from a downloaded
* subscription.
*/
private static final String[] ALLOWED_META_KEYS_ARRAY =
{
"checksum", KEY_VERSION, KEY_TITLE, "last modified", "expires", "homepage", "licence"
@@ -87,20 +88,17 @@ final class Subscription
private final HashMap<String, String> meta = new HashMap<>();
private final HashSet<String> filters = new HashSet<>();
private boolean metaDataValid = true;
private boolean filtersValid = true;
static
{
- for (final String s : ALLOWED_META_KEYS_ARRAY)
- {
- ALLOWED_META_KEYS.add(s);
- }
+ Collections.addAll(ALLOWED_META_KEYS, ALLOWED_META_KEYS_ARRAY);
anton 2017/06/16 13:38:44 Can we replace: ``` private static final HashSet<S
diegocarloslima 2017/07/19 16:39:24 Yeah its possible to initialize the HashSet withou
}
/**
* Subscription type.
*
* @author René Jeschke &lt;rene@adblockplus.org&gt;
*/
public enum Type
@@ -353,19 +351,19 @@ final class Subscription
return "user:" + subscription.getMeta(KEY_TITLE);
}
return "";
}
private static String byteArrayToHexString(final byte[] array)
{
final StringBuilder sb = new StringBuilder(array.length * 2);
- for (int i = 0; i < array.length; i++)
+ for (final byte b : array)
{
- final int value = array[i] & 255;
+ final int value = b & 255;
if (value < 16)
{
sb.append('0');
}
sb.append(Integer.toHexString(value));
}
return sb.toString();
}
@@ -399,33 +397,33 @@ final class Subscription
{
throw new IOException("MD5 is unavailable: " + e.getMessage(), e);
}
}
public void serializeMetaData(final File metaFile) throws IOException
{
this.putMeta(KEY_META_HASH, createMetaDataHash(this.meta));
- try (final DataOutputStream metaOut = new DataOutputStream(new GZIPOutputStream(
- new BufferedOutputStream(new FileOutputStream(metaFile)))))
+ try (final DataOutputStream metaOut = new DataOutputStream(new BufferedOutputStream(
+ new GZIPOutputStream(new FileOutputStream(metaFile)))))
{
metaOut.writeUTF(this.url != null ? this.url.toString() : "");
metaOut.writeInt(this.meta.size());
for (final Entry<String, String> e : this.meta.entrySet())
{
metaOut.writeUTF(e.getKey());
metaOut.writeUTF(e.getValue());
}
}
}
public void serializeFilters(final File filtersFile) throws IOException
{
- try (final DataOutputStream filtersOut = new DataOutputStream(new GZIPOutputStream(
- new BufferedOutputStream(new FileOutputStream(filtersFile)))))
+ try (final DataOutputStream filtersOut = new DataOutputStream(new BufferedOutputStream(
+ new GZIPOutputStream(new FileOutputStream(filtersFile)))))
{
filtersOut.writeInt(this.filters.size());
filtersOut.writeUTF(createFilterHash(new ArrayList<>(this.filters)));
for (final String s : this.filters)
{
final byte[] b = s.getBytes(StandardCharsets.UTF_8);
filtersOut.writeInt(b.length);
filtersOut.write(b);
@@ -437,17 +435,17 @@ final class Subscription
{
this.serializeMetaData(metaFile);
this.serializeFilters(filtersFile);
}
public static Subscription deserializeSubscription(final File metaFile)
{
Subscription sub = null;
- try (final DataInputStream in = new DataInputStream(new GZIPInputStream(new BufferedInputStream(
+ try (final DataInputStream in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(
new FileInputStream(metaFile)))))
{
final String urlString = in.readUTF();
sub = new Subscription(!TextUtils.isEmpty(urlString) ? new URL(urlString) : null);
sub.metaDataValid = false;
final int numMetaEntries = in.readInt();
for (int i = 0; i < numMetaEntries; i++)
{
@@ -463,17 +461,17 @@ final class Subscription
}
return sub;
}
public void deserializeFilters(final File filtersFile)
{
this.clearFilters();
this.filtersValid = false;
- try (final DataInputStream in = new DataInputStream(new GZIPInputStream(new BufferedInputStream(
+ try (final DataInputStream in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(
new FileInputStream(filtersFile)))))
{
final int numFilters = in.readInt();
final String filtersHash = in.readUTF();
for (int i = 0; i < numFilters; i++)
{
final int length = in.readInt();
final byte[] b = new byte[length];

Powered by Google App Engine
This is Rietveld