diff --git a/example/src/main/java/top/zibin/luban/example/MainActivity.java b/example/src/main/java/top/zibin/luban/example/MainActivity.java index a7f397d..eaa6c24 100644 --- a/example/src/main/java/top/zibin/luban/example/MainActivity.java +++ b/example/src/main/java/top/zibin/luban/example/MainActivity.java @@ -75,7 +75,10 @@ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.sync_files: - withRx(assetsToFiles()); + List 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 List apply(@NonNull List list) throws Exception { } }) .observeOn(AndroidSchedulers.mainThread()) + .doOnError(new Consumer() { + @Override + public void accept(Throwable throwable) { + Log.e(TAG, throwable.getMessage()); + } + }) + .onErrorResumeNext(Flowable.>empty()) .subscribe(new Consumer>() { @Override public void accept(@NonNull List list) { diff --git a/library/src/main/java/top/zibin/luban/Checker.java b/library/src/main/java/top/zibin/luban/Checker.java index f5a8407..da43c7c 100644 --- a/library/src/main/java/top/zibin/luban/Checker.java +++ b/library/src/main/java/top/zibin/luban/Checker.java @@ -155,19 +155,24 @@ && pack(jpeg, offset + 6, 2, false) == 0) { 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) {