You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by no...@apache.org on 2020/10/26 11:56:03 UTC
[cordova-plugin-file] branch master updated: refactor(android):
Removed obsolete copyResource function (#433)
This is an automated email from the ASF dual-hosted git repository.
normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git
The following commit(s) were added to refs/heads/master by this push:
new a73fc11 refactor(android): Removed obsolete copyResource function (#433)
a73fc11 is described below
commit a73fc113a7297344facbf57f0697d2bae5d94ba4
Author: Norman Breau <no...@normanbreau.com>
AuthorDate: Mon Oct 26 08:55:54 2020 -0300
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 051f994..393344f 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -272,7 +272,7 @@ public class LocalFilesystem extends Filesystem {
}
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 class LocalFilesystem extends Filesystem {
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();
- }
- }
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org