<commit_before>package com.wordwise.client;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import org.restlet.Client;
import org.restlet.Context;
import org.restlet.data.Protocol;
import org.restlet.engine.Engine;
import org.restlet.ext.jackson.JacksonConverter;
import org.restlet.resource.ClientResource;

import android.content.res.Resources;
import android.util.Log;

import com.wordwise.R;
import com.wordwise.gameengine.ServerCommunication;
import com.wordwise.server.dto.DTODifficulty;
import com.wordwise.server.dto.DTOLanguage;
import com.wordwise.server.dto.DTOQuality;
import com.wordwise.server.dto.DTORate;
import com.wordwise.server.dto.DTOTranslation;
import com.wordwise.server.dto.DTOWord;
import com.wordwise.server.dto.parameter.ListTranslationParameters;
import com.wordwise.server.dto.parameter.ListWordParameters;
import com.wordwise.server.resource.DifficultyResource;
import com.wordwise.server.resource.QualityResource;
import com.wordwise.server.resource.RateResource;
import com.wordwise.server.resource.TranslationResource;
import com.wordwise.server.resource.WordResource;

public class RESTfullServerCommunication implements ServerCommunication {
	
	private String BASE_CLIENT_URL;
	
	private Integer timeout = 5000;
	private String timeoutString = timeout.toString();
	
	public RESTfullServerCommunication(android.content.Context context){
		BASE_CLIENT_URL = baseClientURL(context);
	}
	
	public String baseClientURL(android.content.Context context){
		Resources resources = context.getResources();
		InputStream rawResource = resources.openRawResource(R.raw.wordwise_server);
		Properties prop = new Properties();        
		try {
		    prop.load(rawResource);
			String protocol = prop.getProperty("protocol", "http");
			String serverBaseAddress = prop.getProperty("server-base-address", "");
			String appName = prop.getProperty("appName", "WordWiseServer");
			
			return protocol + "://" + serverBaseAddress + "/" + appName + "/";
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	private TranslationResource getTranslationResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        Client client = new Client(context, Protocol.HTTP);
        ClientResource clientResource = new ClientResource(BASE_CLIENT_URL + TranslationResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);
		clientResource.setNext(client);

		return clientResource.wrap(TranslationResource.class);
	}

	private RateResource getRateResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        Client client = new Client(context, Protocol.HTTP);
        ClientResource clientResource = new ClientResource(BASE_CLIENT_URL + RateResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);
		clientResource.setNext(client);

		return clientResource.wrap(RateResource.class);
	}

	private QualityResource getQualityResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        Client client = new Client(context, Protocol.HTTP);
        ClientResource clientResource = new ClientResource(BASE_CLIENT_URL + QualityResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);
		clientResource.setNext(client);

		return clientResource.wrap(QualityResource.class);
	}

	private DifficultyResource getDifficultyResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        Client client = new Client(context, Protocol.HTTP);
        ClientResource clientResource = new ClientResource(BASE_CLIENT_URL + DifficultyResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);
		clientResource.setNext(client);

		return clientResource.wrap(DifficultyResource.class);
	}
	
	private WordResource getWordResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        Client client = new Client(context, Protocol.HTTP);
        ClientResource clientResource = new ClientResource(BASE_CLIENT_URL + WordResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);
		clientResource.setNext(client);

		return clientResource.wrap(WordResource.class);<commit_msg>bug fix (possible fix for the memory leak problem :)  )<commit_after>package com.wordwise.client;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import org.restlet.Context;
import org.restlet.engine.Engine;
import org.restlet.ext.jackson.JacksonConverter;
import org.restlet.resource.ClientResource;

import android.content.res.Resources;
import android.util.Log;

import com.wordwise.R;
import com.wordwise.gameengine.ServerCommunication;
import com.wordwise.server.dto.DTODifficulty;
import com.wordwise.server.dto.DTOLanguage;
import com.wordwise.server.dto.DTOQuality;
import com.wordwise.server.dto.DTORate;
import com.wordwise.server.dto.DTOTranslation;
import com.wordwise.server.dto.DTOWord;
import com.wordwise.server.dto.parameter.ListTranslationParameters;
import com.wordwise.server.dto.parameter.ListWordParameters;
import com.wordwise.server.resource.DifficultyResource;
import com.wordwise.server.resource.QualityResource;
import com.wordwise.server.resource.RateResource;
import com.wordwise.server.resource.TranslationResource;
import com.wordwise.server.resource.WordResource;

public class RESTfullServerCommunication implements ServerCommunication {
	
	private String BASE_CLIENT_URL;
	
	private Integer timeout = 5000;
	private String timeoutString = timeout.toString();
	
	public RESTfullServerCommunication(android.content.Context context){
		BASE_CLIENT_URL = baseClientURL(context);
	}
	
	public String baseClientURL(android.content.Context context){
		Resources resources = context.getResources();
		InputStream rawResource = resources.openRawResource(R.raw.wordwise_server);
		Properties prop = new Properties();        
		try {
		    prop.load(rawResource);
			String protocol = prop.getProperty("protocol", "http");
			String serverBaseAddress = prop.getProperty("server-base-address", "");
			String appName = prop.getProperty("appName", "WordWiseServer");
			
			return protocol + "://" + serverBaseAddress + "/" + appName + "/";
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	private TranslationResource getTranslationResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        ClientResource clientResource = new ClientResource(context, BASE_CLIENT_URL + TranslationResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);

		return clientResource.wrap(TranslationResource.class);
	}

	private RateResource getRateResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        ClientResource clientResource = new ClientResource(context, BASE_CLIENT_URL + RateResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);

		return clientResource.wrap(RateResource.class);
	}

	private QualityResource getQualityResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        ClientResource clientResource = new ClientResource(context, BASE_CLIENT_URL + QualityResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);

		return clientResource.wrap(QualityResource.class);
	}

	private DifficultyResource getDifficultyResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        ClientResource clientResource = new ClientResource(context, BASE_CLIENT_URL + DifficultyResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);

		return clientResource.wrap(DifficultyResource.class);
	}
	
	private WordResource getWordResource() {
		Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
		
		Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", timeoutString);
        context.getParameters().add("maxIoIdleTimeMs", timeoutString);
        context.getParameters().add("socketTimeout", timeoutString);
        ClientResource clientResource = new ClientResource(context, BASE_CLIENT_URL + WordResource.RESOURCE_NAME);
		clientResource.setRetryOnError(false);

		return clientResource.wrap(WordResource.class);
{'fraction_non_alphanumeric': 0.10833022039596563, 'fraction_numerical': 0.0007471049682480389, 'mean_word_length': 5.494238932686477, 'pattern_counts': {'":': 2, '<': 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': '824446', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2816, 'n_words': 505}