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

Unified Diff: src/org/adblockplus/android/AndroidWebRequest.java

Issue 4980445527670784: Issue 303 - Don't load element hiding rules (Closed)
Patch Set: Created Oct. 1, 2014, 2:45 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/android/AndroidWebRequest.java
diff --git a/src/org/adblockplus/android/AndroidWebRequest.java b/src/org/adblockplus/android/AndroidWebRequest.java
index 35102acc610982d0bc7b5aad471bd9cf1431628a..c477ea7ffb8ec523c75ad75cc5e437da24fcd200 100644
--- a/src/org/adblockplus/android/AndroidWebRequest.java
+++ b/src/org/adblockplus/android/AndroidWebRequest.java
@@ -17,7 +17,8 @@
package org.adblockplus.android;
-import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
@@ -34,9 +35,6 @@ public class AndroidWebRequest extends WebRequest
{
public final String TAG = Utils.getTag(WebRequest.class);
- private static final int INITIAL_BUFFER_SIZE = 65536;
- private static final int BUFFER_GROWTH_DELTA = 65536;
-
@Override
public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> headers)
{
@@ -54,34 +52,26 @@ public class AndroidWebRequest extends WebRequest
if (response.getResponseStatus() == 200)
{
- final InputStream in = connection.getInputStream();
-
- final byte[] buffer = new byte[4096];
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
+ final StringBuilder sb = new StringBuilder();
- byte[] out = new byte[INITIAL_BUFFER_SIZE];
+ String line;
- int pos = 0;
- for (;;)
+ while ((line = reader.readLine()) != null)
{
- final int read = in.read(buffer);
- if (read < 0)
- {
- break;
- }
- if (pos + read > out.length)
+ // We're only appending non-element-hiding filters here.
+ // See: https://issues.adblockplus.org/ticket/303
+ if (line.indexOf('#') == -1)
Felix Dahlke 2014/10/01 15:34:12 This is quite problematic IMO, since we're not onl
René Jeschke 2014/10/01 15:37:48 1. I can check for .txt files, but I don't know if
{
- final byte[] old = out;
- out = new byte[out.length + BUFFER_GROWTH_DELTA];
- System.arraycopy(old, 0, out, 0, pos);
+ sb.append(line);
+ sb.append('\n');
}
- System.arraycopy(buffer, 0, out, pos, read);
- pos += read;
}
connection.disconnect();
response.setStatus(NsStatus.OK);
- response.setResponse(new String(out, 0, pos, "utf-8"));
+ response.setResponse(sb.toString());
}
else
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld