From 9d984b6e563df963b70e3fdb7ad91075fe35a2cb Mon Sep 17 00:00:00 2001 From: Simon B Date: Sun, 7 Mar 2021 10:48:05 +0100 Subject: [PATCH] Use FileUtils.copy Untested! This assumes we have `compileSdkVersion 29` or higher. This copy method might be faster, or if noting else, less own code to maintain. I found this since the code scanner warned of potential memory leak (unclosed file descriptors) if copying fails. If using FileUtils won't work, we should add a `finally` block that ensures the Streams get closed and garbage collected. --- .../src/main/java/com/blixtwallet/LndMobileTools.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/android/app/src/main/java/com/blixtwallet/LndMobileTools.java b/android/app/src/main/java/com/blixtwallet/LndMobileTools.java index f2e6a558a..76e289970 100644 --- a/android/app/src/main/java/com/blixtwallet/LndMobileTools.java +++ b/android/app/src/main/java/com/blixtwallet/LndMobileTools.java @@ -316,16 +316,7 @@ public String copyLndLogFile() { } } - InputStream in = new FileInputStream(sourceLocation); - OutputStream out = new FileOutputStream(targetLocation); - - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - in.close(); - out.close(); + FileUtils.copy(new FileInputStream(source), new FileOutputStream(destination)); return targetLocation.toString(); } catch (Throwable e) {