// Path: app/src/main/java/org/pquery/webdriver/CancelledListener.java
// public interface CancelledListener {
//     void ifCancelledThrow() throws InterruptedException;
// }
// 
// Path: app/src/main/java/org/pquery/webdriver/HttpClientFactory.java
// public class HttpClientFactory {
// 
// //    public static DefaultHttpClient createHttpClient() {
// //
// //        // Set timeout
// //        // I have seen some random failures where the network access just seems to lock-up for over a minute
// //        // I can't reproduce it but hopefully this will make it error and allow user to manually retry
// //        final HttpParams httpParams = new BasicHttpParams();
// //        HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
// //        HttpConnectionParams.setSoTimeout(httpParams, 10000);
// //
// //        return new DefaultHttpClient(httpParams);
// //    }
// 
//     public static HttpURLConnection createURLConnection(URL url) throws IOException {
//         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 
//         // Set timeout
//         // I have seen some random failures where the network access just seems to lock-up
//         // ... for minutes
//         // I can't reproduce it but hopefully this will make it error out and allow user to manually
//         // retry
//         conn.setReadTimeout(20000);         // 20 seconds
//         conn.setConnectTimeout(20000);      // 20 seconds
// 
//         conn.setRequestProperty("Accept-Encoding", "gzip");
//         conn.setRequestProperty("Host", "www.geocaching.com");
// 
//         // Makes our job a bit easier trying to work out what is going on with login problems etc.
//         conn.setInstanceFollowRedirects(false);
// 
//         return conn;
//     }
// }


import android.content.Context;
import android.util.Pair;
import org.pquery.webdriver.CancelledListener;
import org.pquery.webdriver.HttpClientFactory;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpCookie;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
package org.pquery.util;





public class IOUtils {


    private static final String SET_COOKIE = "Set-Cookie";


    /**
     * Used to store response from downloading a file
     */
    public static class FileDetails {
        public String filename;        // sent to us from far end server in the HTTP headers response
        public byte[] contents;
    }


    private static final int ESTIMATED_COMPRESSION_RATIO = 5;
    private static final int ESTIMATED_CONTENT_SIZE = 48000;

    public interface Listener {
        void update(int bytesReadSoFar, int expectedLength, int percent);
    }


// Path: app/src/main/java/org/pquery/webdriver/CancelledListener.java
// public interface CancelledListener {
//     void ifCancelledThrow() throws InterruptedException;
// }
// 
// Path: app/src/main/java/org/pquery/webdriver/HttpClientFactory.java
// public class HttpClientFactory {
// 
// //    public static DefaultHttpClient createHttpClient() {
// //
// //        // Set timeout
// //        // I have seen some random failures where the network access just seems to lock-up for over a minute
// //        // I can't reproduce it but hopefully this will make it error and allow user to manually retry
// //        final HttpParams httpParams = new BasicHttpParams();
// //        HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
// //        HttpConnectionParams.setSoTimeout(httpParams, 10000);
// //
// //        return new DefaultHttpClient(httpParams);
// //    }
// 
//     public static HttpURLConnection createURLConnection(URL url) throws IOException {
//         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 
//         // Set timeout
//         // I have seen some random failures where the network access just seems to lock-up
//         // ... for minutes
//         // I can't reproduce it but hopefully this will make it error out and allow user to manually
//         // retry
//         conn.setReadTimeout(20000);         // 20 seconds
//         conn.setConnectTimeout(20000);      // 20 seconds
// 
//         conn.setRequestProperty("Accept-Encoding", "gzip");
//         conn.setRequestProperty("Host", "www.geocaching.com");
// 
//         // Makes our job a bit easier trying to work out what is going on with login problems etc.
//         conn.setInstanceFollowRedirects(false);
// 
//         return conn;
//     }
// }


// Path: app/src/main/java/org/pquery/util/IOUtils.java
import android.content.Context;
import android.util.Pair;
import org.pquery.webdriver.CancelledListener;
import org.pquery.webdriver.HttpClientFactory;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpCookie;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;

package org.pquery.util;





public class IOUtils {


    private static final String SET_COOKIE = "Set-Cookie";


    /**
     * Used to store response from downloading a file
     */
    public static class FileDetails {
        public String filename;        // sent to us from far end server in the HTTP headers response
        public byte[] contents;
    }


    private static final int ESTIMATED_COMPRESSION_RATIO = 5;
    private static final int ESTIMATED_CONTENT_SIZE = 48000;

    public interface Listener {
        void update(int bytesReadSoFar, int expectedLength, int percent);
    }


    public static byte[] toByteArray(InputStream input, CancelledListener cancelledListener, Listener listener, int expectedLength) throws IOException, InterruptedException {