// Path: src/com/pocketreddit/library/Constants.java
// public class Constants {
//     private Constants() {
//     }
//     
//     public static final String SYSTEM_PROPERTY_USER_AGENT = "com.pocketreddit.library.useragent";
// }
// 
// Path: src/com/pocketreddit/library/utils/StreamUtils.java
// public class StreamUtils {
//     private static StreamUtils instance;
// 
//     private StreamUtils() {
//     }
// 
//     public static StreamUtils getInstance() {
//         if (instance == null) {
//             instance = new StreamUtils();
//         }
// 
//         return instance;
//     }
// 
//     public String convertStreamToString(InputStream is) throws UtilsException {
//         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
//         String line;
//         StringBuilder sb = new StringBuilder();
// 
//         try {
//             while ((line = reader.readLine()) != null) {
//                 sb.append(line + "\n");
//             }
//         } catch (IOException e) {
//             throw new UtilsException("Couldn't read line from stream.", e);
//         } finally {
//             try {
//                 if (is != null)
//                     is.close();
//             } catch (IOException e) {
//                 // TODO Auto-generated catch block
//                 e.printStackTrace();
//             }
//         }
// 
//         return sb.toString();
//     }
// }
// 
// Path: src/com/pocketreddit/library/utils/UtilsException.java
// public class UtilsException extends Exception {
//     private static final long serialVersionUID = 1L;
// 
//     public UtilsException(String message) {
//         super(message);
//     }
// 
//     public UtilsException(String message, Throwable throwable) {
//         super(message, throwable);
//     }
// }


import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.params.CoreProtocolPNames;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import com.pocketreddit.library.Constants;
import com.pocketreddit.library.utils.StreamUtils;
import com.pocketreddit.library.utils.UtilsException;
    private HttpClient buildHttpClient(List<Cookie> cookies) {
        DefaultHttpClient client = new DefaultHttpClient();

        String userAgent = System.getProperty(Constants.SYSTEM_PROPERTY_USER_AGENT);

        if (userAgent != null)
            client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);

        if (cookies != null && !cookies.isEmpty()) {
            client.setCookieStore(buildCookieStore(cookies));
        }

        return client;
    }

    private CookieStore buildCookieStore(List<Cookie> cookies) {
        Cookie[] cookieArray = new Cookie[cookies.size()];
        return buildCookieStore(cookies.toArray(cookieArray));
    }

    private CookieStore buildCookieStore(Cookie... cookies) {
        CookieStore cookieStore = new BasicCookieStore();
        for (Cookie cookie : cookies) {
            cookieStore.addCookie(cookie);
        }

        return cookieStore;
    }

    private JSONArray getJsonArrayFromResponse(HttpResponse response) throws IllegalStateException,
// Path: src/com/pocketreddit/library/Constants.java
// public class Constants {
//     private Constants() {
//     }
//     
//     public static final String SYSTEM_PROPERTY_USER_AGENT = "com.pocketreddit.library.useragent";
// }
// 
// Path: src/com/pocketreddit/library/utils/StreamUtils.java
// public class StreamUtils {
//     private static StreamUtils instance;
// 
//     private StreamUtils() {
//     }
// 
//     public static StreamUtils getInstance() {
//         if (instance == null) {
//             instance = new StreamUtils();
//         }
// 
//         return instance;
//     }
// 
//     public String convertStreamToString(InputStream is) throws UtilsException {
//         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
//         String line;
//         StringBuilder sb = new StringBuilder();
// 
//         try {
//             while ((line = reader.readLine()) != null) {
//                 sb.append(line + "\n");
//             }
//         } catch (IOException e) {
//             throw new UtilsException("Couldn't read line from stream.", e);
//         } finally {
//             try {
//                 if (is != null)
//                     is.close();
//             } catch (IOException e) {
//                 // TODO Auto-generated catch block
//                 e.printStackTrace();
//             }
//         }
// 
//         return sb.toString();
//     }
// }
// 
// Path: src/com/pocketreddit/library/utils/UtilsException.java
// public class UtilsException extends Exception {
//     private static final long serialVersionUID = 1L;
// 
//     public UtilsException(String message) {
//         super(message);
//     }
// 
//     public UtilsException(String message, Throwable throwable) {
//         super(message, throwable);
//     }
// }


// Path: src/com/pocketreddit/library/net/HttpHelper.java
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.params.CoreProtocolPNames;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import com.pocketreddit.library.Constants;
import com.pocketreddit.library.utils.StreamUtils;
import com.pocketreddit.library.utils.UtilsException;

    private HttpClient buildHttpClient(List<Cookie> cookies) {
        DefaultHttpClient client = new DefaultHttpClient();

        String userAgent = System.getProperty(Constants.SYSTEM_PROPERTY_USER_AGENT);

        if (userAgent != null)
            client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);

        if (cookies != null && !cookies.isEmpty()) {
            client.setCookieStore(buildCookieStore(cookies));
        }

        return client;
    }

    private CookieStore buildCookieStore(List<Cookie> cookies) {
        Cookie[] cookieArray = new Cookie[cookies.size()];
        return buildCookieStore(cookies.toArray(cookieArray));
    }

    private CookieStore buildCookieStore(Cookie... cookies) {
        CookieStore cookieStore = new BasicCookieStore();
        for (Cookie cookie : cookies) {
            cookieStore.addCookie(cookie);
        }

        return cookieStore;
    }

    private JSONArray getJsonArrayFromResponse(HttpResponse response) throws IllegalStateException,
            JSONException, IOException, UtilsException {