<commit_before>package org.literacyapp.appstore.util;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import org.apache.commons.io.IOUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Downloads APK files from the web server.
 */
public class ApkLoader {

    public static File loadApk(String urlValue, String fileName, Context context) {
        Log.i(ApkLoader.class.getName(), "loadApk");

        Log.i(ApkLoader.class.getName(), "Downloading from " + urlValue + "...");

        File apkDirectory = new File(Environment.getExternalStorageDirectory() + "/.literacyapp-appstore/apks");
        Log.i(ApkLoader.class.getName(), "apkDirectory: " + apkDirectory);
        if (!apkDirectory.exists()) {
            apkDirectory.mkdirs();
        }

        File apkFile = new File(apkDirectory, fileName);
        Log.i(ApkLoader.class.getName(), "apkFile: " + apkFile);
        Log.i(ApkLoader.class.getName(), "apkFile.exists(): " + apkFile.exists());

        if (!apkFile.exists()) {
            FileOutputStream fileOutputStream = null;
            try {
                URL url = new URL(urlValue);

                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("GET");
                httpURLConnection.connect();

                int responseCode = httpURLConnection.getResponseCode();
                Log.i(ApkLoader.class.getName(), "responseCode: " + responseCode);
                InputStream inputStream = null;
                if (responseCode == 200) {
                    inputStream = httpURLConnection.getInputStream();
                } else {
                    inputStream = httpURLConnection.getErrorStream();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                    String errorResponse = "";
                    String line;
                    while ((line = bufferedReader.readLine()) != null) {
                        errorResponse += line;
                    }
                    Log.w(ApkLoader.class.getName(), "errorResponse: " + errorResponse);
                    return null;
                }

                byte[] bytes = IOUtils.toByteArray(inputStream);
                fileOutputStream = new FileOutputStream(apkFile);
                fileOutputStream.write(bytes);
                fileOutputStream.flush();
            } catch (MalformedURLException e) {
                Log.e(ApkLoader.class.getName(), "MalformedURLException", e);
            } catch (IOException e) {
                Log.e(ApkLoader.class.getName(), "IOException", e);
            } finally {
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e) {
                        Log.e(ApkLoader.class.getName(), "IOException", e);
                    }
                }
            }
        }

        return apkFile;
    }
}<commit_msg>big file download fix<commit_after>package org.literacyapp.appstore.util;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Downloads APK files from the web server.
 */
public class ApkLoader {

    public static File loadApk(String urlValue, String fileName, Context context) {
        Log.i(ApkLoader.class.getName(), "loadApk");

        Log.i(ApkLoader.class.getName(), "Downloading from " + urlValue + "...");

        File apkDirectory = new File(Environment.getExternalStorageDirectory() + "/.literacyapp-appstore/apks");
        Log.i(ApkLoader.class.getName(), "apkDirectory: " + apkDirectory);
        if (!apkDirectory.exists()) {
            apkDirectory.mkdirs();
        }

        File apkFile = new File(apkDirectory, fileName);
        Log.i(ApkLoader.class.getName(), "apkFile: " + apkFile);
        Log.i(ApkLoader.class.getName(), "apkFile.exists(): " + apkFile.exists());

        if (!apkFile.exists()) {
             try {
                URL url = new URL(urlValue);

                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("GET");
                httpURLConnection.connect();

                int responseCode = httpURLConnection.getResponseCode();
                Log.i(ApkLoader.class.getName(), "responseCode: " + responseCode);
                if (responseCode == 200) {
                    //read file's chunks and write them to file, instead of writing file to variable
                    //there isn't file size limit
                    //for details visit apache-commons documentation
                    FileUtils.copyURLToFile(url, apkFile);
                } else {
                    InputStream inputStream = httpURLConnection.getErrorStream();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                    String errorResponse = "";
                    String line;
                    while ((line = bufferedReader.readLine()) != null) {
                        errorResponse += line;
                    }
                    Log.w(ApkLoader.class.getName(), "errorResponse: " + errorResponse);
                    return null;
                }
            } catch (MalformedURLException e) {
                Log.e(ApkLoader.class.getName(), "MalformedURLException", e);
            } catch (IOException e) {
                Log.e(ApkLoader.class.getName(), "IOException", e);
            }
        }
        return apkFile;
    }
}
{'fraction_non_alphanumeric': 0.10986186957918406, 'fraction_numerical': 0.0009637006103437199, 'mean_word_length': 2.046477495107632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1371223', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1555, 'n_words': 328}