Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/com/qiniu/demo/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.qiniu.rs.CallRet;
import com.qiniu.rs.PutExtra;
import com.qiniu.rs.UploadCallRet;
import com.qiniu.utils.QiniuException;

/**
* 也可参考 UploadTest
Expand Down Expand Up @@ -96,13 +95,9 @@ public void onSuccess(UploadCallRet ret) {
}

@Override
public void onFailure(CallRet ret, QiniuException ex) {
public void onFailure(CallRet ret) {
uploading = false;
hint.setText("错误: " + (ret != null ? ret.toString() : ex.toString()));
ex.printStackTrace();
if(ex.reason != null){
ex.reason.printStackTrace();
}
hint.setText("错误: " + ret.toString());
}
});
}
Expand Down
9 changes: 2 additions & 7 deletions src/com/qiniu/demo/MyResumableActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.qiniu.rs.PutExtra;
import com.qiniu.rs.UploadCallRet;
import com.qiniu.rs.UploadTaskExecutor;
import com.qiniu.utils.QiniuException;

public class MyResumableActivity extends Activity implements View.OnClickListener {

Expand Down Expand Up @@ -126,14 +125,10 @@ public void onBlockSuccess(Block blk){
}

@Override
public void onFailure(CallRet ret, QiniuException ex) {
public void onFailure(CallRet ret) {
uploading = false;
clean();
hint.setText(pre + "错误: " + (ret != null ? ret.toString() : ex.toString()));
ex.printStackTrace();
if(ex.reason != null){
ex.reason.printStackTrace();
}
hint.setText(pre + "错误: " + ret.toString());
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/com/qiniu/io/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import android.net.Uri;

import com.qiniu.auth.Authorizer;
import com.qiniu.conf.Conf;
import com.qiniu.rs.CallBack;
import com.qiniu.rs.CallRet;
import com.qiniu.rs.PutExtra;
import com.qiniu.rs.UploadTaskExecutor;
import com.qiniu.utils.InputStreamAt;
import com.qiniu.utils.QiniuException;

public class IO {

Expand All @@ -35,7 +36,7 @@ public static UploadTaskExecutor put(Authorizer auth,
task.execute();
return new UploadTaskExecutor(task);
} catch (IOException e) {
callback.onFailure(null, new QiniuException(QiniuException.IO, "build multipart", e));
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
return null;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/com/qiniu/resumableio/ResumableIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import android.net.Uri;

import com.qiniu.auth.Authorizer;
import com.qiniu.conf.Conf;
import com.qiniu.resumableio.SliceUploadTask.Block;
import com.qiniu.rs.CallBack;
import com.qiniu.rs.CallRet;
import com.qiniu.rs.PutExtra;
import com.qiniu.rs.UploadTaskExecutor;
import com.qiniu.utils.InputStreamAt;
import com.qiniu.utils.QiniuException;

public class ResumableIO {

Expand Down Expand Up @@ -52,7 +53,7 @@ public static UploadTaskExecutor put(Authorizer auth, String key,
task.execute();
return new UploadTaskExecutor(task);
} catch (IOException e) {
callback.onFailure(null, new QiniuException(QiniuException.IO, "build multipart", e));
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", e));
return null;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/com/qiniu/rs/CallBack.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.qiniu.rs;

import com.qiniu.resumableio.SliceUploadTask.Block;
import com.qiniu.utils.QiniuException;

public abstract class CallBack {

public abstract void onProcess(long current, long total);
public abstract void onSuccess(UploadCallRet ret);
public abstract void onFailure(CallRet ret, QiniuException ex);
public abstract void onFailure(CallRet ret);
public void onBlockSuccess(Block blk){}

}
13 changes: 4 additions & 9 deletions src/com/qiniu/rs/CallRet.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.qiniu.rs;

import com.qiniu.utils.QiniuException;

public class CallRet {
private final int statusCode;
private final String reqId;
private final String response;
private QiniuException exception;
private Exception exception;

/**
* 子类必须实现此构造函数
Expand All @@ -31,11 +30,7 @@ public CallRet(int errorCode, String reqId, Exception e) {
this.statusCode = errorCode;
this.reqId = reqId;
this.response = "";
if(e instanceof QiniuException){
exception = (QiniuException)e;
}else{
this.exception = new QiniuException(statusCode, response, e);
}
exception = e;
doUnmarshal();
}

Expand All @@ -48,7 +43,7 @@ private void doUnmarshal() {
unmarshal();
} catch (Exception e) {
if (this.exception == null) {
this.exception = new QiniuException(QiniuException.JSON, "", e);;
this.exception = e;
}
}
}
Expand All @@ -70,7 +65,7 @@ public String getReqId() {
public String getResponse() {
return response;
}
public QiniuException getException() {
public Exception getException() {
return exception;
}

Expand Down
17 changes: 6 additions & 11 deletions src/com/qiniu/utils/InputStreamAt.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,12 @@ private boolean hasFile(){

private void tryContentFile(String path){
if(path != null){
try{file = new File(path);}catch(Exception e){}
if(hasFile()){
return;
}
try{file = new File("/mnt" + path);}catch(Exception e){}
if(hasFile()){
return;
}
try{file = new File("/mnt/" + path);}catch(Exception e){}
if(hasFile()){
return;
String[] ps = {"", "/mnt", "/mnt/"};
for(String p : ps){
try{file = new File(p + path);}catch(Exception e){}
if(hasFile()){
return;
}
}
}
}
Expand Down
41 changes: 0 additions & 41 deletions src/com/qiniu/utils/QiniuException.java

This file was deleted.

6 changes: 3 additions & 3 deletions src/com/qiniu/utils/UploadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ protected void onCancelled(CallRet ret){
protected void onPostExecute(CallRet ret){
try{
if(ret == null){
callback.onFailure(ret, new QiniuException(Conf.ERROR_CODE, "", "result is null"));
callback.onFailure(new CallRet(Conf.ERROR_CODE, "", "result is null"));
return;
}
if(ret.getException() != null){
callback.onFailure(ret, ret.getException());
callback.onFailure(ret);
}else if(ret.isOk()){
callback.onSuccess(new UploadCallRet(ret));
}else{
callback.onFailure(ret, new QiniuException(ret.getStatusCode(), ret.getReqId(), ret.getResponse()));
callback.onFailure(ret);
}
}catch(Exception e){
e.printStackTrace();
Expand Down
4 changes: 2 additions & 2 deletions src/com/qiniu/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public static HttpPost newPost(String url){
}

public static boolean needChangeUpAdress(CallRet ret){
if(ret.getException() != null && ret.getException().reason != null){
if(ret.getException() != null){
try {
throw ret.getException().reason;
throw ret.getException();
} catch (java.net.UnknownHostException e) {

} catch (java.net.NoRouteToHostException e) {
Expand Down
17 changes: 3 additions & 14 deletions tests/src/com/qiniu/test/UploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.qiniu.rs.CallBack;
import com.qiniu.rs.UploadCallRet;
import com.qiniu.rs.UploadTaskExecutor;
import com.qiniu.utils.QiniuException;
import com.qiniu.auth.Authorizer;
import com.qiniu.conf.Conf;

Expand All @@ -46,7 +45,7 @@ public class UploadTest extends AndroidTestCase {
private volatile boolean success;
private volatile CallBack jsonRet;
private volatile UploadCallRet resp;
private volatile QiniuException e;
private volatile Exception e;

private Context context;
private volatile Uri uri;
Expand Down Expand Up @@ -94,11 +93,10 @@ public void onSuccess(UploadCallRet ret) {
}

@Override
public void onFailure(CallRet ret, QiniuException ex) {
public void onFailure(CallRet ret) {
uploading = false;
success = false;
e = ex;
Log.d("UploadTest", "上传失败! " + (ret != null ? ret.toString() : ex.toString()));
Log.d("UploadTest", "上传失败! " + ret.toString());
sem.release();
}

Expand Down Expand Up @@ -174,9 +172,6 @@ public void testIOCancel() throws IOException, JSONException, InterruptedExcepti
System.out.println(ret.getResponse());
if(ret.getException() != null){
ret.getException().fillInStackTrace();
if(ret.getException().reason != null){
ret.getException().reason.fillInStackTrace();
}
}
}
Assert.assertTrue((end - s) < 1000 * 5);
Expand Down Expand Up @@ -304,9 +299,6 @@ public void run() {

if(e != null){
e.printStackTrace();
if(e.reason != null){
e.reason.printStackTrace();
}
}
successCheck();
//Assert.assertTrue(time > 1);
Expand All @@ -316,9 +308,6 @@ public void run() {
private void successCheck() throws JSONException{
if(e != null){
e.printStackTrace();
if(e.reason != null){
e.reason.printStackTrace();
}
}
Assert.assertTrue(success);
Assert.assertNotNull(resp.getHash());
Expand Down