MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / copyFile

Method copyFile

src/plugins/sdcard/src/android/SDcard.java:894–923  ·  view source on GitHub ↗
(DocumentFile src, DocumentFile dest)

Source from the content-addressed store, hash-verified

892 }
893
894 private Uri copyFile(DocumentFile src, DocumentFile dest)
895 throws IOException, FileNotFoundException {
896 ContentResolver contentResolver = this.context.getContentResolver();
897
898 Uri newFileUri = DocumentsContract.createDocument(
899 contentResolver,
900 dest.getUri(),
901 src.getType(),
902 src.getName()
903 );
904 DocumentFile newFile = getFile(newFileUri);
905 InputStream is = contentResolver.openInputStream(src.getUri());
906 OutputStream os = contentResolver.openOutputStream(newFile.getUri(), "rwt");
907
908 if (is == null || os == null) {
909 DocumentsContract.deleteDocument(contentResolver, newFileUri);
910 return null;
911 }
912
913 IOUtils.copy(is, os);
914
915 is.close();
916 os.close();
917
918 if (src.length() == newFile.length()) return newFile.getUri();
919 else {
920 DocumentsContract.deleteDocument(contentResolver, newFileUri);
921 return null;
922 }
923 }
924
925 private void listDir(String src, String parentId, CallbackContext callback) {
926 cordova

Callers 1

copyMethod · 0.95

Calls 7

getFileMethod · 0.95
createDocumentMethod · 0.80
getUriMethod · 0.80
getTypeMethod · 0.80
deleteDocumentMethod · 0.80
copyMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected