Skip to content

Commit

Permalink
增加压缩失败返回异常中包含原路径
Browse files Browse the repository at this point in the history
  • Loading branch information
Gru110110110 committed Jun 27, 2017
1 parent fd6d815 commit 68209a0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Step 1. Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency
```gradle
dependencies {
compile 'com.github.pruas:Biscuit:v1.0.2'
compile 'com.github.pruas:Biscuit:v1.0.3'
}
```
Step 3. Use it wherever you need
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/seek/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.bumptech.glide.Glide;
import com.seek.biscuit.Biscuit;
import com.seek.biscuit.CompressException;
import com.seek.biscuit.CompressListener;

import java.util.ArrayList;
Expand Down Expand Up @@ -45,7 +46,8 @@ public void onSuccess(String compressedPath) {

@Override
public void onError(Exception e) {
Log.e(">>>>>", e.getMessage());
CompressException err = (CompressException) e;
Log.e(">>>>>", "message : "+e.getMessage()+" original Path : "+err.originalPath);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0.2"
versionName "1.0.3"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
20 changes: 20 additions & 0 deletions library/src/main/java/com/seek/biscuit/CompressException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.seek.biscuit;

/**
* Created by seek on 2017/6/27.
*/

public class CompressException extends Exception {

public String originalPath = null;

public CompressException(String message, String path) {
super(message);
originalPath = path;
}

public CompressException(String message, String path, Throwable cause) {
super(message, cause);
originalPath = path;
}
}
9 changes: 6 additions & 3 deletions library/src/main/java/com/seek/biscuit/ImageCompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ public boolean compress() {
fos.close();
stream.close();
} catch (IOException e) {
log(TAG, "there is an exception when trying to save the compressed image!");
exception = e;
String msg = "there is an exception when trying to save the compressed image!";
log(TAG, msg);
String path = sourcePath.path;
exception = new CompressException(msg, path, e);
saved = false;
} finally {
if (exception != null && !saved) {
Expand Down Expand Up @@ -161,7 +163,8 @@ private void dispatchError() {

private void generateException(String msg) {
log(TAG, msg);
exception = new IllegalArgumentException(msg);
String path = sourcePath.path;
exception = new CompressException(msg, path);
dispatchError();
}

Expand Down

0 comments on commit 68209a0

Please sign in to comment.