Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: Removed obsolete copyResource function #433

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(android): Removed obsolete copyResource function
  • Loading branch information
breautek committed Oct 22, 2020
commit 904c413a6464f600ec8ed0a1942eaee7c0b60baf
42 changes: 1 addition & 41 deletions src/android/LocalFilesystem.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}