<commit_before>package com.mobilesolutionworks.android.httpcache;

import android.app.IntentService;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mobilesolutionworks.android.http.WorksHttpAsyncTask;
import com.mobilesolutionworks.android.http.WorksHttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by yunarta on 31/7/14.
 */
public abstract class WorksHttpCacheService extends IntentService
{
    protected Set<Uri> mQueues;

    protected String mGetDataIntent;

    protected Gson mGson;

    protected ExecutorService mExecutors;

    public WorksHttpCacheService()
    {
        super("cache-service");
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        mQueues = new HashSet<Uri>();
        mExecutors = Executors.newCachedThreadPool();

        Bundle metaData;
        try
        {
            ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            metaData = ai.metaData;
        }
        catch (PackageManager.NameNotFoundException e)
        {
            metaData = new Bundle();
            metaData.putString("getDataIntent", "GET_DATA_INTENT");
        }

        mGetDataIntent = metaData.getString("getDataIntent");
        mGson = new GsonBuilder().create();
    }

    @Override
    protected void onHandleIntent(Intent intent)
    {
        if (intent != null)
        {
            String action = intent.getAction();
            if (mGetDataIntent.equals(action))
            {
                refreshData(intent);
            }
        }
    }

    protected abstract String createUrl(Uri data, String[] args);

    protected abstract int resolveUri(Uri data);

    protected abstract Uri createUri(String path);

    protected void refreshData(Intent intent)
    {
        Uri data = Uri.parse(intent.getData().toString());

        Log.d("WorksHttpCache", "going to fetch for " + data);
        if (resolveUri(data) == -1)
        {
            return;
        }

        if (mQueues.contains(data))
        {
            return;
        }

        mQueues.add(data);

        String[] args = intent.getStringArrayExtra("args");
        if (args == null)
        {
            args = new String[0];
        }

        WorksHttpRequest config = new WorksHttpRequest();
        config.method = WorksHttpRequest.Method.POST;
        config.url = createUrl(data, args);

        String params = intent.getStringExtra("params");
        if (!TextUtils.isEmpty(params))
        {
            JsonObject parse = mGson.fromJson(params, JsonObject.class);
            for (Map.Entry<String, JsonElement> entry : parse.entrySet())
            {
                config.setPostParam(entry.getKey(), entry.getValue().getAsString());
            }
        }

        String cache = data.getQueryParameter("cache");
        long time = 2 * 60;
        if (!TextUtils.isEmpty(cache))
        {
            time = Long.parseLong(cache);
            if (time == 0)<commit_msg>empty parameter values will not be added to post param<commit_after>package com.mobilesolutionworks.android.httpcache;

import android.app.IntentService;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mobilesolutionworks.android.http.WorksHttpAsyncTask;
import com.mobilesolutionworks.android.http.WorksHttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by yunarta on 31/7/14.
 */
public abstract class WorksHttpCacheService extends IntentService
{
    protected Set<Uri> mQueues;

    protected String mGetDataIntent;

    protected Gson mGson;

    protected ExecutorService mExecutors;

    public WorksHttpCacheService()
    {
        super("cache-service");
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        mQueues = new HashSet<Uri>();
        mExecutors = Executors.newCachedThreadPool();

        Bundle metaData;
        try
        {
            ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            metaData = ai.metaData;
        }
        catch (PackageManager.NameNotFoundException e)
        {
            metaData = new Bundle();
            metaData.putString("getDataIntent", "GET_DATA_INTENT");
        }

        mGetDataIntent = metaData.getString("getDataIntent");
        mGson = new GsonBuilder().create();
    }

    @Override
    protected void onHandleIntent(Intent intent)
    {
        if (intent != null)
        {
            String action = intent.getAction();
            if (mGetDataIntent.equals(action))
            {
                refreshData(intent);
            }
        }
    }

    protected abstract String createUrl(Uri data, String[] args);

    protected abstract int resolveUri(Uri data);

    protected abstract Uri createUri(String path);

    protected void refreshData(Intent intent)
    {
        Uri data = Uri.parse(intent.getData().toString());

        Log.d("WorksHttpCache", "going to fetch for " + data);
        if (resolveUri(data) == -1)
        {
            return;
        }

        if (mQueues.contains(data))
        {
            return;
        }

        mQueues.add(data);

        String[] args = intent.getStringArrayExtra("args");
        if (args == null)
        {
            args = new String[0];
        }

        WorksHttpRequest config = new WorksHttpRequest();
        config.method = WorksHttpRequest.Method.POST;
        config.url = createUrl(data, args);

        String params = intent.getStringExtra("params");
        if (!TextUtils.isEmpty(params))
        {
            JsonObject parse = mGson.fromJson(params, JsonObject.class);
            for (Map.Entry<String, JsonElement> entry : parse.entrySet())
            {
                String value = entry.getValue().getAsString();
                if (!TextUtils.isEmpty(value)) {
                    config.setPostParam(entry.getKey(), value);
                }
            }
        }

        String cache = data.getQueryParameter("cache");
        long time = 2 * 60;
        if (!TextUtils.isEmpty(cache))
        {
            time = Long.parseLong(cache);
            if (time == 0)
{'fraction_non_alphanumeric': 0.10448535130930775, 'fraction_numerical': 0.002851957479906663, 'mean_word_length': 2.547126436781609, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1224324', 'n_tokens_mistral': 2163, 'n_tokens_neox': 2092, 'n_words': 441}