Skip to content

Commit 229779b

Browse files
committed
update
1 parent 1100647 commit 229779b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/com/qiniu/auth/Client.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import org.apache.http.HttpEntity;
88
import org.apache.http.HttpResponse;
99
import org.apache.http.client.HttpClient;
10+
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
11+
import org.apache.http.client.methods.HttpGet;
1012
import org.apache.http.client.methods.HttpPost;
13+
import org.apache.http.client.methods.HttpRequestBase;
1114
import org.apache.http.conn.ClientConnectionManager;
1215
import org.apache.http.conn.scheme.PlainSocketFactory;
1316
import org.apache.http.conn.scheme.Scheme;
@@ -28,6 +31,11 @@ public Client(HttpClient client) {
2831
mClient = client;
2932
}
3033

34+
public static ClientExecutor get(String url, CallRet ret) {
35+
Client client = Client.defaultClient();
36+
return client.get(client.makeClientExecutor(), url, ret);
37+
}
38+
3139
public ClientExecutor call(ClientExecutor client, String url, HttpEntity entity, CallRet ret) {
3240
Header header = entity.getContentType();
3341
String contentType = "application/octet-stream";
@@ -47,26 +55,30 @@ public ClientExecutor call(ClientExecutor client, String url, String contentType
4755
return execute(client, httppost, ret);
4856
}
4957

58+
public ClientExecutor get(ClientExecutor client, String url, CallRet ret) {
59+
return execute(client, new HttpGet(url), ret);
60+
}
61+
5062
public ClientExecutor makeClientExecutor() {
5163
return new ClientExecutor();
5264
}
5365

54-
protected ClientExecutor execute(ClientExecutor client, HttpPost httpPost, final CallRet ret) {
55-
client.setup(httpPost, ret);
66+
protected ClientExecutor execute(ClientExecutor client, HttpRequestBase httpRequest, final CallRet ret) {
67+
client.setup(httpRequest, ret);
5668
client.execute();
5769
return client;
5870
}
5971

60-
protected HttpResponse roundtrip(HttpPost httpPost) throws IOException {
61-
httpPost.setHeader("User-Agent", Conf.USER_AGENT);
62-
return mClient.execute(httpPost);
72+
protected HttpResponse roundtrip(HttpRequestBase httpRequest) throws IOException {
73+
httpRequest.setHeader("User-Agent", Conf.USER_AGENT);
74+
return mClient.execute(httpRequest);
6375
}
6476

6577
public class ClientExecutor extends AsyncTask<Object, Object, Object> implements ICancel {
66-
HttpPost mHttpPost;
78+
HttpRequestBase mHttpRequest;
6779
CallRet mRet;
68-
public void setup(HttpPost httpPost, CallRet ret) {
69-
mHttpPost = httpPost;
80+
public void setup(HttpRequestBase httpRequest, CallRet ret) {
81+
mHttpRequest = httpRequest;
7082
mRet = ret;
7183
}
7284
public void upload(long current, long total) {
@@ -76,10 +88,10 @@ public void upload(long current, long total) {
7688
@Override
7789
protected Object doInBackground(Object... objects) {
7890
try {
79-
HttpResponse resp = roundtrip(mHttpPost);
91+
HttpResponse resp = roundtrip(mHttpRequest);
8092
int statusCode = resp.getStatusLine().getStatusCode();
8193
if (statusCode == 401) { // android 2.3 will not response
82-
return new Exception(resp.getStatusLine().getReasonPhrase());
94+
return new Exception("unauthorized!");
8395
}
8496
byte[] data = EntityUtils.toByteArray(resp.getEntity());
8597

src/com/qiniu/utils/MultipartEntity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public void writeTo(OutputStream outputStream) throws IOException {
110110
writed += data.length;
111111
if (mNotify != null) mNotify.onProcess(writed, getContentLength());
112112

113-
int blockSize = 256 * 1024;
113+
int blockSize = (int) (getContentLength() / 100);
114+
if (blockSize > 256 * 1024) blockSize = 256 * 1024;
115+
if (blockSize < 16 * 1024) blockSize = 16 * 1024;
114116
long index = 0;
115117
long length = mIsa.length();
116118
while (index < length) {

0 commit comments

Comments
 (0)