Parcourir la source

Merge pull request #25 from zephyrpersonal/fix/fileutils-copy-lag

fix: improve copy method to prevent lagging
Albert Luo il y a 5 ans
Parent
révision
c4af9ec8e2
No account linked to committer's email address
1 fichiers modifiés avec 7 ajouts et 3 suppressions
  1. 7
    3
      android/src/main/java/com/reactlibrary/utils/FileUtils.java

+ 7
- 3
android/src/main/java/com/reactlibrary/utils/FileUtils.java Voir le fichier

@@ -24,10 +24,14 @@ public class FileUtils {
24 24
             InputStream is = context.getContentResolver().openInputStream(srcUri);
25 25
             if (is == null) return;
26 26
             OutputStream fos = new FileOutputStream(dstFile);
27
-            int ch = 0;
27
+
28
+            byte[] bytes = new byte[1024];
29
+
30
+            int count = is.read(bytes, 0, 1024);
28 31
             try {
29
-                while((ch=is.read()) != -1){
30
-                    fos.write(ch);
32
+                while (count > 0){
33
+                    fos.write(bytes, 0, count);
34
+                    count = is.read(bytes, 0, 1024);
31 35
                 }
32 36
             } catch (IOException e1) {
33 37
                 e1.printStackTrace();