package com.rnziparchive;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import static com.facebook.common.internal.Preconditions.checkNotNull;

public class StreamUtil {
    private static final int BUF_SIZE = 0x1000; // 4K

    public interface ProgressCallback {
        // not the total - the actual number read since last time
        void onCopyProgress(long bytesRead);
    }

    // https://stackoverflow.com/questions/4919690/how-to-read-one-stream-into-another
    public static long copy(InputStream from, OutputStream to, ProgressCallback callback)
            throws IOException {
        checkNotNull(from);
        checkNotNull(to);
        byte[] buf = new byte[BUF_SIZE];
        long total = 0;
        while (true) {
            int r = from.read(buf);
            if (r == -1) {
                break;
            }
            to.write(buf, 0, r);
            total += r;

            if (callback != null) {
                callback.onCopyProgress(r);
            }
        }
        return total;
    }
}

@@ -204,18 +204,16 @@
 mUtil %7B%0A
-  
   privat
@@ -257,18 +257,16 @@
  // 4K%0A%0A
-  
   public
@@ -295,20 +295,16 @@
 lback %7B%0A
-    
     // n
@@ -357,20 +357,16 @@
 st time%0A
-    
     void
@@ -402,19 +402,15 @@
 d);%0A
-  
   %7D%0A%0A  
- 
- 
 // h
@@ -488,18 +488,16 @@
 another%0A
-  
   public
@@ -575,28 +575,16 @@
 allback)
-%0A           
  throws 
@@ -597,20 +597,16 @@
 ption %7B%0A
-    
     chec
@@ -621,20 +621,16 @@
 (from);%0A
-    
     chec
@@ -643,20 +643,16 @@
 ll(to);%0A
-    
     byte
@@ -684,20 +684,16 @@
 E%5D;%0A    
-   
- 
 long tot
@@ -704,20 +704,16 @@
  0;%0A    
-   
- 
 while (t
@@ -725,22 +725,16 @@
 %7B%0A      
-  
-    
 int r = 
@@ -751,30 +751,24 @@
 buf);%0A      
-   
-   
 if (r == -1)
@@ -766,32 +766,24 @@
 (r == -1) %7B%0A
-        
         brea
@@ -791,30 +791,18 @@
 ;%0A      
-    
-  %7D%0A      
+%7D%0A
       to
@@ -816,30 +816,24 @@
 buf, 0, r);%0A
-      
       total 
@@ -845,22 +845,16 @@
 %0A%0A      
- 
-     
 if (call
@@ -877,24 +877,16 @@
         
-   
-     
 callback
@@ -915,30 +915,16 @@
     
-  
-    %7D%0A   
+%7D%0A
     
- 
 %7D%0A
-    
     
@@ -937,16 +937,14 @@
  total;%0A
-  
   %7D%0A%7D%0A

unify indent of java code