Skip to content

Commit 7ff6f4b

Browse files
committed
Merge pull request #66 from simon-liubin/update/check-ex
捕获异常,回调到onFailure中
2 parents 8a2c667 + 31548e7 commit 7ff6f4b

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/com/qiniu/io/IO.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.qiniu.io;
22

33
import java.io.File;
4-
import java.io.FileNotFoundException;
5-
import java.io.IOException;
64

75
import android.content.Context;
86
import android.net.Uri;
@@ -21,12 +19,22 @@ public class IO {
2119

2220
public static UploadTaskExecutor putFile(Context mContext,
2321
Authorizer auth, String key, Uri uri, PutExtra extra, CallBack callback) {
24-
return put(auth, key, InputStreamAt.fromUri(mContext, uri), extra, callback);
22+
try {
23+
return put(auth, key, InputStreamAt.fromUri(mContext, uri), extra, callback);
24+
} catch (Exception e) {
25+
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
26+
return null;
27+
}
2528
}
2629

2730
public static UploadTaskExecutor putFile(Authorizer auth, String key,
28-
File file, PutExtra extra, CallBack callback) throws FileNotFoundException {
29-
return put(auth, key, InputStreamAt.fromFile(file), extra, callback);
31+
File file, PutExtra extra, CallBack callback) {
32+
try {
33+
return put(auth, key, InputStreamAt.fromFile(file), extra, callback);
34+
} catch (Exception e) {
35+
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
36+
return null;
37+
}
3038
}
3139

3240
public static UploadTaskExecutor put(Authorizer auth,
@@ -35,7 +43,7 @@ public static UploadTaskExecutor put(Authorizer auth,
3543
SimpleUploadTask task = new SimpleUploadTask(auth, input, key, extra, callback);
3644
task.execute();
3745
return new UploadTaskExecutor(task);
38-
} catch (IOException e) {
46+
} catch (Exception e) {
3947
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
4048
return null;
4149
}

src/com/qiniu/resumableio/ResumableIO.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.qiniu.resumableio;
22

33
import java.io.File;
4-
import java.io.FileNotFoundException;
5-
import java.io.IOException;
64
import java.util.List;
75

86
import android.content.Context;
@@ -27,17 +25,27 @@ public static UploadTaskExecutor putFile(Context mContext,
2725
public static UploadTaskExecutor putFile(Context mContext,
2826
Authorizer auth, String key, Uri uri, PutExtra extra,
2927
List<Block> blocks, CallBack callback) {
30-
return put(auth, key, InputStreamAt.fromUri(mContext, uri), extra, blocks, callback);
28+
try {
29+
return put(auth, key, InputStreamAt.fromUri(mContext, uri), extra, blocks, callback);
30+
} catch (Exception e) {
31+
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
32+
return null;
33+
}
3134
}
3235

3336
public static UploadTaskExecutor putFile(Authorizer auth, String key,
34-
File file, PutExtra extra, CallBack callback) throws FileNotFoundException {
37+
File file, PutExtra extra, CallBack callback) {
3538
return putFile(auth, key, file, extra, null, callback);
3639
}
3740

38-
public static UploadTaskExecutor putFile(Authorizer auth, String key, File file,
39-
PutExtra extra, List<Block> blocks, CallBack callback) throws FileNotFoundException {
40-
return put(auth, key, InputStreamAt.fromFile(file), extra, blocks, callback);
41+
public static UploadTaskExecutor putFile(Authorizer auth, String key,
42+
File file, PutExtra extra, List<Block> blocks, CallBack callback) {
43+
try{
44+
return put(auth, key, InputStreamAt.fromFile(file), extra, blocks, callback);
45+
} catch (Exception e) {
46+
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
47+
return null;
48+
}
4149
}
4250

4351
public static UploadTaskExecutor put(Authorizer auth, String key,
@@ -52,7 +60,7 @@ public static UploadTaskExecutor put(Authorizer auth, String key,
5260
task.setLastUploadBlocks(blocks);
5361
task.execute();
5462
return new UploadTaskExecutor(task);
55-
} catch (IOException e) {
63+
} catch (Exception e) {
5664
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
5765
return null;
5866
}

0 commit comments

Comments
 (0)