From a73fc113a7297344facbf57f0697d2bae5d94ba4 Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Mon, 26 Oct 2020 08:55:54 -0300 Subject: [PATCH] refactor(android): Removed obsolete copyResource function (#433) --- src/android/LocalFilesystem.java | 42 +------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java index 051f99496..393344f4f 100644 --- a/src/android/LocalFilesystem.java +++ b/src/android/LocalFilesystem.java @@ -272,7 +272,7 @@ private void copyFile(Filesystem srcFs, LocalFilesystemURL srcURL, File destFile } CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(srcFs.toNativeUri(srcURL)); - copyResource(offr, new FileOutputStream(destFile)); + resourceApi.copyResource(offr, new FileOutputStream(destFile)); if (move) { srcFs.removeFileAtLocalURL(srcURL); @@ -470,44 +470,4 @@ public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) { File file = new File(path); return file.exists(); } - - // This is a copy & paste from CordovaResource API that is required since CordovaResourceApi - // has a bug pre-4.0.0. - // TODO: Once cordova-android@4.0.0 is released, delete this copy and make the plugin depend on - // 4.0.0 with an engine tag. - private static void copyResource(CordovaResourceApi.OpenForReadResult input, OutputStream outputStream) throws IOException { - try { - InputStream inputStream = input.inputStream; - if (inputStream instanceof FileInputStream && outputStream instanceof FileOutputStream) { - FileChannel inChannel = ((FileInputStream)input.inputStream).getChannel(); - FileChannel outChannel = ((FileOutputStream)outputStream).getChannel(); - long offset = 0; - long length = input.length; - if (input.assetFd != null) { - offset = input.assetFd.getStartOffset(); - } - // transferFrom()'s 2nd arg is a relative position. Need to set the absolute - // position first. - inChannel.position(offset); - outChannel.transferFrom(inChannel, 0, length); - } else { - final int BUFFER_SIZE = 8192; - byte[] buffer = new byte[BUFFER_SIZE]; - - for (;;) { - int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE); - - if (bytesRead <= 0) { - break; - } - outputStream.write(buffer, 0, bytesRead); - } - } - } finally { - input.inputStream.close(); - if (outputStream != null) { - outputStream.close(); - } - } - } }