From 63bb81999253e4ad85765c1206252abba2a60cc6 Mon Sep 17 00:00:00 2001 From: chenjianpeng Date: Tue, 15 Jun 2021 18:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0checkstyle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yalantis/ucrop/task/BitmapLoadTask.java | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java index 9bbbc81..f0f77a9 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java @@ -190,25 +190,16 @@ public class BitmapLoadTask { private void processInputUri() throws NullPointerException, IOException { String inputUriScheme = mInputUri.getScheme(); if ("http".equals(inputUriScheme) || "https".equals(inputUriScheme)) { - try { + if(mInputUri != null && mOutputUri != null) { downloadFile(mInputUri, mOutputUri); - } catch (NullPointerException e) { - LogUtils.LogError(TAG, "Downloading failed:"+e); - throw e; } } else if ("content".equals(inputUriScheme)) { - try { + if(mInputUri != null && mOutputUri != null) { copyFile(mInputUri, mOutputUri); - } catch (NullPointerException | IOException e) { - LogUtils.LogError(TAG, "Copying failed:"+e); - throw e; } } else if("dataability".equals(inputUriScheme)){ - try { + if(mInputUri != null && mOutputUri != null) { copyFile(mInputUri, mOutputUri); - } catch (NullPointerException | IOException e) { - LogUtils.LogError(TAG, "Copying failed:"+e); - throw e; } } else if (!"file".equals(inputUriScheme)) { LogUtils.LogError(TAG, "Invalid Uri scheme " + inputUriScheme); @@ -216,12 +207,12 @@ public class BitmapLoadTask { } } - private void copyFile(Uri inputUri, Uri outputUri) throws NullPointerException, IOException { + private void copyFile(Uri inputUri, Uri outputUri) throws IOException { LogUtils.LogDebug(TAG, "copyFile"); System.out.println(inputUri); if (outputUri == null) { - throw new NullPointerException("Output Uri is null - cannot copy image"); + return; } InputStream inputStream; @@ -231,18 +222,24 @@ public class BitmapLoadTask { //inputStream = mContext.getContentResolver().openInputStream(inputUri); //通过InputUri获取InputStream DataAbilityHelper helper = DataAbilityHelper.creator(mContext); - FileDescriptor fd_i = helper.openFile(mInputUri, "r"); - inputStream = new FileInputStream(fd_i); - FileDescriptor fd_o = helper.openFile(outputUri,"w"); - outputStream = new FileOutputStream(fd_o); - if (inputStream == null) { - throw new NullPointerException("InputStream for given input Uri is null"); - } + if(helper != null) { + FileDescriptor fd_i = helper.openFile(mInputUri, "r"); + if (fd_i != null) { + inputStream = new FileInputStream(fd_i); + FileDescriptor fd_o = helper.openFile(outputUri, "w"); + if (fd_o != null) { + outputStream = new FileOutputStream(fd_o); + if (inputStream == null) { + return; + } - byte[] buffer = new byte[1024]; - int length; - while ((length = inputStream.read(buffer)) > 0) { - outputStream.write(buffer, 0, length); + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, length); + } + } + } } } catch (DataAbilityRemoteException e) { e.printStackTrace(); @@ -253,11 +250,11 @@ public class BitmapLoadTask { } } - private void downloadFile( Uri inputUri, Uri outputUri) throws NullPointerException, IOException { + private void downloadFile( Uri inputUri, Uri outputUri) throws IOException { LogUtils.LogDebug(TAG, "downloadFile"); if (outputUri == null) { - throw new NullPointerException("Output Uri is null - cannot download image"); + return; } OkHttpClient client = new OkHttpClient(); @@ -278,13 +275,16 @@ public class BitmapLoadTask { //通过OutputUri获取OutputStream OutputStream outputStream; DataAbilityHelper helper = DataAbilityHelper.creator(mContext); - FileDescriptor fd = helper.openFile(outputUri,"w"); - outputStream = new FileOutputStream(fd); - if (outputStream != null) { - sink = Okio.sink(outputStream); - source.readAll(sink); - } else { - throw new NullPointerException("OutputStream for given output Uri is null"); + if(helper != null) { + FileDescriptor fd = helper.openFile(outputUri, "w"); + if (fd != null) { + outputStream = new FileOutputStream(fd); + if (outputStream != null) { + sink = Okio.sink(outputStream); + source.readAll(sink); + } else { + } + } } } catch (DataAbilityRemoteException e) { e.printStackTrace(); -- Gitee