Skip to content

Commit a9ee672

Browse files
committed
Merge pull request #133 from omerjerk/master
Use HttpURLConnection instead of the deprecated classes
2 parents 8e78d2b + 885f6d8 commit a9ee672

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

core/src/processing/core/PApplet.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,12 +4944,19 @@ public InputStream createInputRaw(String filename) {
49444944
// URL url = new URL(filename);
49454945
// stream = url.openStream();
49464946
// return stream;
4947-
HttpGet httpRequest = null;
4948-
httpRequest = new HttpGet(URI.create(filename));
4949-
HttpClient httpclient = new DefaultHttpClient();
4950-
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
4951-
HttpEntity entity = response.getEntity();
4952-
return entity.getContent();
4947+
URL url = new URL(filename);
4948+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
4949+
con.setRequestMethod("GET");
4950+
con.setDoInput(true);
4951+
con.connect();
4952+
return con.getInputStream();
4953+
//The following code is deprecaded by Android
4954+
// HttpGet httpRequest = null;
4955+
// httpRequest = new HttpGet(URI.create(filename));
4956+
// HttpClient httpclient = new DefaultHttpClient();
4957+
// HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
4958+
// HttpEntity entity = response.getEntity();
4959+
// return entity.getContent();
49534960
// can't use BufferedHttpEntity because it may try to allocate a byte
49544961
// buffer of the size of the download, bad when DL is 25 MB... [0200]
49554962
// BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);

0 commit comments

Comments
 (0)