Skip to content

Commit ad3fdbf

Browse files
committed
2 parents 2647f18 + bc461a0 commit ad3fdbf

File tree

12 files changed

+513
-49
lines changed

12 files changed

+513
-49
lines changed

src/AndroidClient/android/src/main/java/net/servicestack/android/AndroidServiceClient.java

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.servicestack.client.AsyncServiceClient;
99
import net.servicestack.client.IReturn;
1010
import net.servicestack.client.JsonServiceClient;
11+
import net.servicestack.client.Utils;
1112

1213
import java.lang.reflect.Type;
1314
import java.net.HttpURLConnection;
@@ -111,24 +112,24 @@ protected void onPostExecute(T response) {
111112
}, path);
112113
}
113114

114-
public void getAsync(String path, final AsyncResult<HttpURLConnection> asyncResult) {
115+
public void getAsync(String path, final AsyncResult<byte[]> asyncResult) {
115116
final AndroidServiceClient client = this;
116-
execTask(new AsyncTask<String, Void, HttpURLConnection>() {
117+
execTask(new AsyncTask<String, Void, byte[]>() {
117118
@Override
118-
protected HttpURLConnection doInBackground(String... params) {
119+
protected byte[] doInBackground(String... params) {
119120
try {
120-
return client.get(params[0]);
121+
HttpURLConnection httpRes = client.get(params[0]);
122+
return Utils.readBytesToEnd(httpRes);
121123
} catch (Exception e) {
122124
asyncResult.setError(e);
123125
return null;
124126
}
125127
}
126128

127129
@Override
128-
protected void onPostExecute(HttpURLConnection response) {
129-
asyncResult.completeResult(response);
130+
protected void onPostExecute(byte[] bytes) {
131+
asyncResult.completeResult(bytes);
130132
}
131-
132133
}, path);
133134
}
134135

@@ -245,22 +246,23 @@ protected void onPostExecute(T response) {
245246
}
246247

247248
@Override
248-
public void postAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<HttpURLConnection> asyncResult) {
249+
public void postAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<byte[]> asyncResult) {
249250
final AndroidServiceClient client = this;
250-
execTask(new AsyncTask<String, Void, HttpURLConnection>() {
251+
execTask(new AsyncTask<String, Void, byte[]>() {
251252
@Override
252-
protected HttpURLConnection doInBackground(String... params) {
253+
protected byte[] doInBackground(String... params) {
253254
try {
254-
return client.post(params[0], requestBody, contentType);
255+
HttpURLConnection httpRes = client.post(params[0], requestBody, contentType);
256+
return Utils.readBytesToEnd(httpRes);
255257
} catch (Exception e) {
256258
asyncResult.setError(e);
257259
return null;
258260
}
259261
}
260262

261263
@Override
262-
protected void onPostExecute(HttpURLConnection response) {
263-
asyncResult.completeResult(response);
264+
protected void onPostExecute(byte[] bytes) {
265+
asyncResult.completeResult(bytes);
264266
}
265267

266268
}, path);
@@ -379,22 +381,23 @@ protected void onPostExecute(T response) {
379381
}
380382

381383
@Override
382-
public void putAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<HttpURLConnection> asyncResult) {
384+
public void putAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<byte[]> asyncResult) {
383385
final AndroidServiceClient client = this;
384-
execTask(new AsyncTask<String, Void, HttpURLConnection>() {
386+
execTask(new AsyncTask<String, Void, byte[]>() {
385387
@Override
386-
protected HttpURLConnection doInBackground(String... params) {
388+
protected byte[] doInBackground(String... params) {
387389
try {
388-
return client.put(params[0], requestBody, contentType);
390+
HttpURLConnection httpRes = client.put(params[0], requestBody, contentType);
391+
return Utils.readBytesToEnd(httpRes);
389392
} catch (Exception e) {
390393
asyncResult.setError(e);
391394
return null;
392395
}
393396
}
394397

395398
@Override
396-
protected void onPostExecute(HttpURLConnection response) {
397-
asyncResult.completeResult(response);
399+
protected void onPostExecute(byte[] bytes) {
400+
asyncResult.completeResult(bytes);
398401
}
399402

400403
}, path);
@@ -487,22 +490,23 @@ protected void onPostExecute(T response) {
487490
}, path);
488491
}
489492

490-
public void deleteAsync(String path, final AsyncResult<HttpURLConnection> asyncResult) {
493+
public void deleteAsync(String path, final AsyncResult<byte[]> asyncResult) {
491494
final AndroidServiceClient client = this;
492-
execTask(new AsyncTask<String, Void, HttpURLConnection>() {
495+
execTask(new AsyncTask<String, Void, byte[]>() {
493496
@Override
494-
protected HttpURLConnection doInBackground(String... params) {
497+
protected byte[] doInBackground(String... params) {
495498
try {
496-
return client.delete(params[0]);
499+
HttpURLConnection httpRes = client.delete(params[0]);
500+
return Utils.readBytesToEnd(httpRes);
497501
} catch (Exception e) {
498502
asyncResult.setError(e);
499503
return null;
500504
}
501505
}
502506

503507
@Override
504-
protected void onPostExecute(HttpURLConnection response) {
505-
asyncResult.completeResult(response);
508+
protected void onPostExecute(byte[] bytes) {
509+
asyncResult.completeResult(bytes);
506510
}
507511

508512
}, path);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.servicestack.android;
2+
3+
import android.graphics.Bitmap;
4+
import android.graphics.BitmapFactory;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.net.HttpURLConnection;
9+
10+
public class AndroidUtils {
11+
public static Bitmap readBitmap(HttpURLConnection response){
12+
try {
13+
return readBitmap(response.getInputStream());
14+
} catch (IOException e) {
15+
throw new RuntimeException(e);
16+
}
17+
}
18+
19+
public static Bitmap readBitmap(InputStream stream) {
20+
return BitmapFactory.decodeStream(stream);
21+
}
22+
23+
public static Bitmap readBitmap(byte[] bytes) {
24+
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
25+
}
26+
}

src/AndroidClient/client/src/main/java/net/servicestack/client/AsyncServiceClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ public interface AsyncServiceClient {
99
public <T> void getAsync(IReturn<T> request, final Map<String, String> queryParams, final AsyncResult<T> asyncResult);
1010
public <T> void getAsync(String path, final Class responseType, final AsyncResult<T> asyncResult);
1111
public <T> void getAsync(String path, final Type responseType, final AsyncResult<T> asyncResult);
12-
public void getAsync(String path, final AsyncResult<HttpURLConnection> asyncResult);
12+
public void getAsync(String path, final AsyncResult<byte[]> asyncResult);
1313

1414
public <T> void postAsync(IReturn<T> request, final AsyncResult<T> asyncResult);
1515
public <T> void postAsync(String path, final Object request, final Class responseType, final AsyncResult<T> asyncResult);
1616
public <T> void postAsync(String path, final Object request, final Type responseType, final AsyncResult<T> asyncResult);
1717
public <T> void postAsync(String path, final byte[] requestBody, final String contentType, final Class responseType, final AsyncResult<T> asyncResult);
1818
public <T> void postAsync(String path, final byte[] requestBody, final String contentType, final Type responseType, final AsyncResult<T> asyncResult);
19-
public void postAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<HttpURLConnection> asyncResult);
19+
public void postAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<byte[]> asyncResult);
2020

2121
public <T> void putAsync(IReturn<T> request, final AsyncResult<T> asyncResult);
2222
public <T> void putAsync(String path, final Object request, final Class responseType, final AsyncResult<T> asyncResult);
2323
public <T> void putAsync(String path, final Object request, final Type responseType, final AsyncResult<T> asyncResult);
2424
public <T> void putAsync(String path, final byte[] requestBody, final String contentType, final Class responseType, final AsyncResult<T> asyncResult);
2525
public <T> void putAsync(String path, final byte[] requestBody, final String contentType, final Type responseType, final AsyncResult<T> asyncResult);
26-
public void putAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<HttpURLConnection> asyncResult);
26+
public void putAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<byte[]> asyncResult);
2727

2828
public <T> void deleteAsync(IReturn<T> request, final AsyncResult<T> asyncResult);
2929
public <T> void deleteAsync(IReturn<T> request, final Map<String, String> queryParams, final AsyncResult<T> asyncResult);
3030
public <T> void deleteAsync(String path, final Class responseType, final AsyncResult<T> asyncResult);
3131
public <T> void deleteAsync(String path, final Type responseType, final AsyncResult<T> asyncResult);
32-
public void deleteAsync(String path, final AsyncResult<HttpURLConnection> asyncResult);
32+
public void deleteAsync(String path, final AsyncResult<byte[]> asyncResult);
3333
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy