Browse Source

fix: improve copy method to prevent lagging

zephyr 6 years ago
parent
commit
a5200b161c
1 changed files with 7 additions and 3 deletions
  1. 7
    3
      android/src/main/java/com/reactlibrary/utils/FileUtils.java

+ 7
- 3
android/src/main/java/com/reactlibrary/utils/FileUtils.java View File

24
             InputStream is = context.getContentResolver().openInputStream(srcUri);
24
             InputStream is = context.getContentResolver().openInputStream(srcUri);
25
             if (is == null) return;
25
             if (is == null) return;
26
             OutputStream fos = new FileOutputStream(dstFile);
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
             try {
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
             } catch (IOException e1) {
36
             } catch (IOException e1) {
33
                 e1.printStackTrace();
37
                 e1.printStackTrace();