<commit_before>package net.sourcewalker.garanbot.api;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EncodingUtils;

import android.util.Base64;

public class GaranboClient {

    private final String username;
    private final String password;
    private final DefaultHttpClient client;
    private final UserService userService;

    public GaranboClient(String username, String password) {
        this.username = username;
        this.password = password;

        client = new DefaultHttpClient();

        userService = new UserService();
    }

    /**
     * Returns true, if the service is available.
     * 
     * @return True, if service is available.
     */
    public boolean ping() {
        try {
            HttpResponse response = get("/ping");
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                return true;
            }
        } catch (IOException e) {
        }
        return false;
    }

    public UserService user() {
        return userService;
    }

    protected HttpResponse get(String path) throws IOException {
        HttpGet request = new HttpGet(ApiConstants.BASE + path);
        prepareRequest(request);
        return client.execute(request);
    }

    private void prepareRequest(HttpGet request) {
        request.addHeader("Content-type", "application/json");
        request.addHeader("Accept", "application/json");
        request.addHeader("open-api", ApiConstants.KEY);
        request.addHeader("Authorization", getAuthHeader());
    }

    private String getAuthHeader() {
        byte[] input = EncodingUtils.getBytes(username + ":" + password,
                "utf-8");
        return Base64.encodeToString(input, Base64.DEFAULT);
    }

    public String readEntity(HttpResponse response) {
        StringBuilder sb = new StringBuilder();
        try {
            InputStream stream = response.getEntity().getContent();
            byte[] buffer = new byte[1024];
            int read;
            do {
                read = stream.read(buffer);
                if (read != -1) {
                    sb.append(EncodingUtils.getString(buffer, "utf-8"));
                }
            } while (read != -1);
        } catch (IOException e) {
            sb.append("ERROR: " + e.getMessage());
        }
        return sb.toString();
    }

}
<commit_msg>Fix incorrect authentication and reading of response.<commit_after>package net.sourcewalker.garanbot.api;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EncodingUtils;

import android.util.Base64;

public class GaranboClient {

    private final String username;
    private final String password;
    private final DefaultHttpClient client;
    private final UserService userService;

    public GaranboClient(String username, String password) {
        this.username = username;
        this.password = password;

        client = new DefaultHttpClient();

        userService = new UserService();
    }

    /**
     * Returns true, if the service is available.
     * 
     * @return True, if service is available.
     */
    public boolean ping() {
        try {
            HttpResponse response = get("/ping");
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                return true;
            }
        } catch (IOException e) {
        }
        return false;
    }

    public UserService user() {
        return userService;
    }

    protected HttpResponse get(String path) throws IOException {
        HttpGet request = new HttpGet(ApiConstants.BASE + path);
        prepareRequest(request);
        return client.execute(request);
    }

    private void prepareRequest(HttpGet request) {
        request.addHeader("Content-type", "application/json");
        request.addHeader("Accept", "application/json");
        request.addHeader("open-api", ApiConstants.KEY);
        request.addHeader("Authorization", getAuthHeader());
    }

    private String getAuthHeader() {
        byte[] input = String.format("%s:%s", username, password).getBytes();
        return "Basic " + Base64.encodeToString(input, Base64.NO_WRAP);
    }

    public String readEntity(HttpResponse response) {
        StringBuilder sb = new StringBuilder();
        try {
            InputStream stream = response.getEntity().getContent();
            byte[] buffer = new byte[1024];
            int read;
            do {
                read = stream.read(buffer);
                if (read != -1) {
                    if (read == buffer.length) {
                        sb.append(EncodingUtils.getString(buffer, "utf-8"));
                    } else {
                        sb.append(EncodingUtils.getString(buffer, 0, read,
                                "utf-8"));
                    }
                }
            } while (read != -1);
        } catch (IOException e) {
            sb.append("ERROR: " + e.getMessage());
        }
        return sb.toString();
    }

}

{'fraction_non_alphanumeric': 0.10783221974758724, 'fraction_numerical': 0.005382331106161841, 'mean_word_length': 2.175604007071302, 'pattern_counts': {'":': 1, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3221863', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1369, 'n_words': 335}