// Path: kraken_lib/src/main/java/com/github/marcosalis/kraken/utils/android/LogUtils.java
// @Beta
// public class LogUtils {
// 
//     @SuppressWarnings("unused")
//     private static final String TAG = LogUtils.class.getSimpleName();
// 
//     private LogUtils() {
//         // hidden constructor, no instantiation needed
//     }
// 
//     /**
//      * Logs a message in LogCat, only if library debugging is active.
//      *
//      * @param logLevel   The log level to use: must be one of the level constants provided by the
//      *                   {@link Log} class.
//      * @param logTag
//      * @param logMessage
//      */
//     public static void log(int logLevel, String logTag, String logMessage) {
//         if (DroidConfig.DEBUG) {
//             switch (logLevel) {
//                 case Log.ASSERT:
//                 case Log.VERBOSE:
//                     Log.v(logTag, logMessage);
//                     break;
//                 case Log.DEBUG:
//                     Log.d(logTag, logMessage);
//                     break;
//                 case Log.INFO:
//                     Log.i(logTag, logMessage);
//                     break;
//                 case Log.WARN:
//                     Log.w(logTag, logMessage);
//                     break;
//                 case Log.ERROR:
//                     Log.e(logTag, logMessage);
//                     break;
//             }
//         }
//     }
// 
//     /**
//      * Prints on LogCat a stack track of an exception, only if library debugging is active.
//      *
//      * @param t The {@link Throwable} to get the stack trace from
//      */
//     public static void logException(Throwable t) {
//         if (DroidConfig.DEBUG) {
//             if (t != null) {
//                 t.printStackTrace();
//             }
//         }
//     }
// 
//     /**
//      * Prints on LogCat a log warning message with the exception stack, only if library debugging is
//      * active.
//      *
//      * @param logTag
//      * @param logMessage
//      * @param t          The {@link Throwable} to get the stack trace from
//      */
//     public static void logException(String logTag, String logMessage, Throwable t) {
//         if (DroidConfig.DEBUG) {
//             if (t != null) {
//                 Log.w(logTag, logMessage, t);
//             }
//         }
//     }
// 
//     /**
//      * Prints on LogCat a log warning message with the exception's message string, only if library
//      * debugging is active.
//      *
//      * @param t The {@link Throwable} to get the message from
//      */
//     public static void logExceptionMessage(String logTag, String logMessage, Throwable t) {
//         if (DroidConfig.DEBUG) {
//             if (t != null) {
//                 Log.w(logTag,
//                         logMessage + "\n" + t.getClass().getSimpleName() + " message: "
//                                 + t.getMessage());
//             }
//         }
//     }
// 
// }


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Callable;
import javax.annotation.concurrent.Immutable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import com.github.marcosalis.kraken.DroidConfig;
import com.github.marcosalis.kraken.utils.android.LogUtils;
import com.github.marcosalis.kraken.utils.annotations.NotForUIThread;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpMethods;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.common.annotations.Beta;
import com.google.common.io.ByteStreams;
    @Nullable
    @NotForUIThread
    public static byte[] downloadByteArray(@NonNull HttpRequestFactory factory, @NonNull String url)
            throws IOException, IllegalArgumentException {
        HttpRequest request = null;
        HttpResponse response = null;
        byte[] bytes = null;

        if (DroidConfig.DEBUG) {
            Log.d(TAG, "Executing GET request to: " + url);
        }

        try {
            request = factory.buildRequest(HttpMethods.GET, new GenericUrl(url), null);
            response = request.execute();

            if (response.isSuccessStatusCode()) {
                // get input stream and converts it to byte array
                InputStream stream = new BufferedInputStream(response.getContent());
                bytes = ByteStreams.toByteArray(stream);

                if (DroidConfig.DEBUG && bytes != null) {
                    Log.v(TAG, "GET request successful to: " + url);
                }
            }
        } finally {
            if (response != null) {
                try {
                    response.disconnect();
                } catch (IOException e) { // just an attempt to close the stream
// Path: kraken_lib/src/main/java/com/github/marcosalis/kraken/utils/android/LogUtils.java
// @Beta
// public class LogUtils {
// 
//     @SuppressWarnings("unused")
//     private static final String TAG = LogUtils.class.getSimpleName();
// 
//     private LogUtils() {
//         // hidden constructor, no instantiation needed
//     }
// 
//     /**
//      * Logs a message in LogCat, only if library debugging is active.
//      *
//      * @param logLevel   The log level to use: must be one of the level constants provided by the
//      *                   {@link Log} class.
//      * @param logTag
//      * @param logMessage
//      */
//     public static void log(int logLevel, String logTag, String logMessage) {
//         if (DroidConfig.DEBUG) {
//             switch (logLevel) {
//                 case Log.ASSERT:
//                 case Log.VERBOSE:
//                     Log.v(logTag, logMessage);
//                     break;
//                 case Log.DEBUG:
//                     Log.d(logTag, logMessage);
//                     break;
//                 case Log.INFO:
//                     Log.i(logTag, logMessage);
//                     break;
//                 case Log.WARN:
//                     Log.w(logTag, logMessage);
//                     break;
//                 case Log.ERROR:
//                     Log.e(logTag, logMessage);
//                     break;
//             }
//         }
//     }
// 
//     /**
//      * Prints on LogCat a stack track of an exception, only if library debugging is active.
//      *
//      * @param t The {@link Throwable} to get the stack trace from
//      */
//     public static void logException(Throwable t) {
//         if (DroidConfig.DEBUG) {
//             if (t != null) {
//                 t.printStackTrace();
//             }
//         }
//     }
// 
//     /**
//      * Prints on LogCat a log warning message with the exception stack, only if library debugging is
//      * active.
//      *
//      * @param logTag
//      * @param logMessage
//      * @param t          The {@link Throwable} to get the stack trace from
//      */
//     public static void logException(String logTag, String logMessage, Throwable t) {
//         if (DroidConfig.DEBUG) {
//             if (t != null) {
//                 Log.w(logTag, logMessage, t);
//             }
//         }
//     }
// 
//     /**
//      * Prints on LogCat a log warning message with the exception's message string, only if library
//      * debugging is active.
//      *
//      * @param t The {@link Throwable} to get the message from
//      */
//     public static void logExceptionMessage(String logTag, String logMessage, Throwable t) {
//         if (DroidConfig.DEBUG) {
//             if (t != null) {
//                 Log.w(logTag,
//                         logMessage + "\n" + t.getClass().getSimpleName() + " message: "
//                                 + t.getMessage());
//             }
//         }
//     }
// 
// }


// Path: kraken_lib/src/main/java/com/github/marcosalis/kraken/utils/http/ByteArrayDownloader.java
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Callable;
import javax.annotation.concurrent.Immutable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import com.github.marcosalis.kraken.DroidConfig;
import com.github.marcosalis.kraken.utils.android.LogUtils;
import com.github.marcosalis.kraken.utils.annotations.NotForUIThread;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpMethods;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.common.annotations.Beta;
import com.google.common.io.ByteStreams;

    @Nullable
    @NotForUIThread
    public static byte[] downloadByteArray(@NonNull HttpRequestFactory factory, @NonNull String url)
            throws IOException, IllegalArgumentException {
        HttpRequest request = null;
        HttpResponse response = null;
        byte[] bytes = null;

        if (DroidConfig.DEBUG) {
            Log.d(TAG, "Executing GET request to: " + url);
        }

        try {
            request = factory.buildRequest(HttpMethods.GET, new GenericUrl(url), null);
            response = request.execute();

            if (response.isSuccessStatusCode()) {
                // get input stream and converts it to byte array
                InputStream stream = new BufferedInputStream(response.getContent());
                bytes = ByteStreams.toByteArray(stream);

                if (DroidConfig.DEBUG && bytes != null) {
                    Log.v(TAG, "GET request successful to: " + url);
                }
            }
        } finally {
            if (response != null) {
                try {
                    response.disconnect();
                } catch (IOException e) { // just an attempt to close the stream
                    LogUtils.logException(e);