<commit_before>package com.github.kubatatami.judonetworking.internals.wear;

import com.github.kubatatami.judonetworking.logs.JudoLogger;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.WearableListenerService;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okio.BufferedSink;

/**
 * Created by Kuba on 28/09/15.
 */
public class HandheldListenerService extends WearableListenerService {

    protected MessageUtils messageUtils;

    protected OkHttpClient baseClient = new OkHttpClient();

    @Override
    public void onCreate() {
        super.onCreate();
        messageUtils = new MessageUtils(this);
    }

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        if (messageEvent.getPath().contains(MessageUtils.MSG_PATH)) {
            WearResponse response = null;
            String id = messageEvent.getPath().substring(MessageUtils.MSG_PATH.length());
            try {
                WearRequest request = messageUtils.readObject(messageEvent.getData(), WearRequest.class);
                response = send(request);
            } catch (IOException e) {
                response = new WearResponse(e);
                JudoLogger.log(e);
            }
            try {
                messageUtils.sendMessage(id, messageEvent.getSourceNodeId(), response);
            } catch (IOException e) {
                JudoLogger.log(e);
            }
        } else {
            super.onMessageReceived(messageEvent);
        }
    }

    protected WearResponse send(final WearRequest request) throws IOException {
        RequestBody requestBody = null;
        OkHttpClient client = baseClient.clone();
        client.setConnectTimeout(request.getConnectTimeout(), TimeUnit.MILLISECONDS);
        client.setReadTimeout(request.getReadTimeout(), TimeUnit.MILLISECONDS);
        Request.Builder builder = new Request.Builder();
        if (request.getBody() != null) {
            requestBody = new RequestBody() {
                @Override
                public MediaType contentType() {
                    return MediaType.parse(request.getMimeType());
                }<commit_msg>throw ConnectionException instead null pointer exception when timeout<commit_after>package com.github.kubatatami.judonetworking.internals.wear;

import com.github.kubatatami.judonetworking.logs.JudoLogger;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.WearableListenerService;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okio.BufferedSink;

/**
 * Created by Kuba on 28/09/15.
 */
public class HandheldListenerService extends WearableListenerService {

    protected MessageUtils messageUtils;

    protected OkHttpClient baseClient = new OkHttpClient();

    @Override
    public void onCreate() {
        super.onCreate();
        messageUtils = new MessageUtils(this);
    }

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        if (messageEvent.getPath().contains(MessageUtils.MSG_PATH)) {
            WearResponse response;
            String id = messageEvent.getPath().substring(MessageUtils.MSG_PATH.length());
            try {
                WearRequest request = messageUtils.readObject(messageEvent.getData(), WearRequest.class);
                response = send(request);
            } catch (IOException e) {
                response = new WearResponse(e);
                JudoLogger.log(e);
            }
            try {
                messageUtils.sendMessage(id, messageEvent.getSourceNodeId(), response);
            } catch (IOException e) {
                JudoLogger.log(e);
            }
        } else {
            super.onMessageReceived(messageEvent);
        }
    }

    protected WearResponse send(final WearRequest request) throws IOException {
        RequestBody requestBody = null;
        OkHttpClient client = baseClient.clone();
        client.setConnectTimeout(request.getConnectTimeout(), TimeUnit.MILLISECONDS);
        client.setReadTimeout(request.getReadTimeout(), TimeUnit.MILLISECONDS);
        Request.Builder builder = new Request.Builder();
        if (request.getBody() != null) {
            requestBody = new RequestBody() {
                @Override
                public MediaType contentType() {
                    return MediaType.parse(request.getMimeType());
                }
{'fraction_non_alphanumeric': 0.09398269269470719, 'fraction_numerical': 0.002414972831555645, 'mean_word_length': 2.7424698795180724, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7493048', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1311, 'n_words': 258}