郑梓斌 6 years ago
parent
commit
a9c10e0027

+ 11 - 1
example/src/main/java/top/zibin/luban/example/MainActivity.java

@@ -75,7 +75,10 @@ public class MainActivity extends AppCompatActivity {
 
     switch (item.getItemId()) {
       case R.id.sync_files:
-        withRx(assetsToFiles());
+        List<File> list = new ArrayList<>();
+        list.add(new File("/data/user/0/1529400069961674"));
+        originPhotos.addAll(list);
+        withRx(list);
         break;
       case R.id.sync_uris:
         withRx(assetsToUri());
@@ -143,6 +146,13 @@ public class MainActivity extends AppCompatActivity {
           }
         })
         .observeOn(AndroidSchedulers.mainThread())
+        .doOnError(new Consumer<Throwable>() {
+          @Override
+          public void accept(Throwable throwable) {
+            Log.e(TAG, throwable.getMessage());
+          }
+        })
+        .onErrorResumeNext(Flowable.<List<File>>empty())
         .subscribe(new Consumer<List<File>>() {
           @Override
           public void accept(@NonNull List<File> list) {

+ 15 - 10
library/src/main/java/top/zibin/luban/Checker.java

@@ -155,19 +155,24 @@ enum Checker {
     return 0;
   }
 
-  String extSuffix(InputStreamProvider input) throws IOException {
-    Bitmap bitmap = BitmapFactory.decodeStream(input.open(), null, new BitmapFactory.Options());
-    String suffix = TextUtils.isEmpty(input.getPath()) ? "" : input.getPath().substring(input.getPath().lastIndexOf("."), input.getPath().length());
+  String extSuffix(InputStreamProvider input) {
+    try {
+      Bitmap bitmap = BitmapFactory.decodeStream(input.open(), null, new BitmapFactory.Options());
+      String suffix = TextUtils.isEmpty(input.getPath()) ? "" :
+          input.getPath().substring(input.getPath().lastIndexOf("."), input.getPath().length());
+
+      if (bitmap.hasAlpha()) {
+        return PNG;
+      } else if (TextUtils.isEmpty(suffix)) {
+        return JPG;
+      } else if (!format.contains(suffix)) {
+        return JPG;
+      }
 
-    if (bitmap.hasAlpha()) {
-      return PNG;
-    } else if (TextUtils.isEmpty(suffix)) {
-      return JPG;
-    } else if (!format.contains(suffix)) {
+      return suffix;
+    } catch (Exception e) {
       return JPG;
     }
-
-    return suffix;
   }
 
   boolean needCompress(int leastCompressSize, String path) {