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

Delta Between Two Patch Sets: src/org/adblockplus/android/AndroidWebRequest.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Removed another whitespace change Created April 28, 2014, 8:36 a.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 import org.adblockplus.libadblockplus.ServerResponse; 27 import org.adblockplus.libadblockplus.ServerResponse;
28 import org.adblockplus.libadblockplus.WebRequest; 28 import org.adblockplus.libadblockplus.WebRequest;
29 import org.adblockplus.libadblockplus.ServerResponse.NsStatus; 29 import org.adblockplus.libadblockplus.ServerResponse.NsStatus;
30 30
31 import android.util.Log; 31 import android.util.Log;
32 32
33 public class AndroidWebRequest extends WebRequest 33 public class AndroidWebRequest extends WebRequest
34 { 34 {
35 public final String TAG = Utils.getTag(WebRequest.class); 35 public final String TAG = Utils.getTag(WebRequest.class);
36 36
37 private static final int INITIAL_BUFFER_SIZE = 65536;
37 private static final int BUFFER_GROWTH_DELTA = 65536; 38 private static final int BUFFER_GROWTH_DELTA = 65536;
38 39
39 @Override 40 @Override
40 public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> hea ders) 41 public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> hea ders)
41 { 42 {
42 try 43 try
43 { 44 {
44 final URL url = new URL(urlStr); 45 final URL url = new URL(urlStr);
45 Log.d(this.TAG, "Downloading from: " + url); 46 Log.d(this.TAG, "Downloading from: " + url);
46 47
47 final HttpURLConnection connection = (HttpURLConnection) url.openConnectio n(); 48 final HttpURLConnection connection = (HttpURLConnection) url.openConnectio n();
48 connection.setRequestMethod("GET"); 49 connection.setRequestMethod("GET");
49 connection.connect(); 50 connection.connect();
50 51
51 final ServerResponse response = new ServerResponse(); 52 final ServerResponse response = new ServerResponse();
52 response.setResponseStatus(connection.getResponseCode()); 53 response.setResponseStatus(connection.getResponseCode());
53 54
54 if (response.getResponseStatus() == 200) 55 if (response.getResponseStatus() == 200)
55 { 56 {
56 final InputStream in = connection.getInputStream(); 57 final InputStream in = connection.getInputStream();
57 58
58 final byte[] buffer = new byte[4096]; 59 final byte[] buffer = new byte[4096];
59 60
60 byte[] out = new byte[65536]; 61 byte[] out = new byte[INITIAL_BUFFER_SIZE];
61 62
62 int pos = 0; 63 int pos = 0;
63 for (;;) 64 for (;;)
64 { 65 {
65 final int read = in.read(buffer); 66 final int read = in.read(buffer);
66 if (read < 0) 67 if (read < 0)
67 { 68 {
68 break; 69 break;
69 } 70 }
70 if (pos + read > out.length) 71 if (pos + read > out.length)
(...skipping 16 matching lines...) Expand all
87 response.setStatus(NsStatus.ERROR_FAILURE); 88 response.setStatus(NsStatus.ERROR_FAILURE);
88 } 89 }
89 return response; 90 return response;
90 } 91 }
91 catch (final Throwable t) 92 catch (final Throwable t)
92 { 93 {
93 throw new AdblockPlusException("WebRequest failed", t); 94 throw new AdblockPlusException("WebRequest failed", t);
94 } 95 }
95 } 96 }
96 } 97 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld