Ver código fonte

fix: improve copy method to prevent lagging

zephyr 6 anos atrás
pai
commit
a5200b161c

+ 7
- 3
android/src/main/java/com/reactlibrary/utils/FileUtils.java Ver arquivo

@@ -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();