<commit_before>package com.zeyad.genericusecase.data.repository;

import android.content.Context;

import com.google.gson.Gson;
import com.zeyad.genericusecase.Config;
import com.zeyad.genericusecase.domain.repositories.Files;

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 rx.Observable;

/**
 * @author by ZIaDo on 11/12/16.
 */

public class FilesRepository implements Files {
    private static Files sInstance;

    private FilesRepository() {
    }

    public static Files getInstance() {
        if (sInstance == null)
            sInstance = new FilesRepository();
        return sInstance;
    }

    @Override
    public Observable<String> readFromResource(String filePath) {
        return Observable.defer(() -> {
            StringBuilder returnString = new StringBuilder();
            InputStream fIn = null;
            InputStreamReader isr = null;
            BufferedReader input = null;
            try {
                fIn = Config.getInstance().getContext().getResources().getAssets().open(filePath);
                isr = new InputStreamReader(fIn);
                input = new BufferedReader(isr);
                String line;
                while ((line = input.readLine()) != null)
                    returnString.append(line);
            } catch (IOException e) {
                e.printStackTrace();
                return Observable.error(e);
            } finally {
                if (isr != null)
                    try {
                        isr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                if (fIn != null)
                    try {
                        fIn.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                if (input != null)
                    try {
                        input.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
            return Observable.just(returnString.toString());
        });
    }

    @Override
    public Observable<String> readFromFile(String fullFilePath) {
        try {
            return Observable.just(new Gson().fromJson(new InputStreamReader(Config.getInstance()<commit_msg>fixed write to file use case<commit_after>package com.zeyad.genericusecase.data.repository;

import android.content.Context;

import com.google.gson.Gson;
import com.zeyad.genericusecase.Config;
import com.zeyad.genericusecase.domain.repositories.Files;

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 rx.Observable;

/**
 * @author by ZIaDo on 11/12/16.
 */

public class FilesRepository implements Files {
    private static Files sInstance;

    private FilesRepository() {
    }

    public static Files getInstance() {
        if (sInstance == null)
            sInstance = new FilesRepository();
        return sInstance;
    }

    @Override
    public Observable<String> readFromResource(String filePath) {
        return Observable.defer(() -> {
            StringBuilder returnString = new StringBuilder();
            InputStream fIn = null;
            InputStreamReader isr = null;
            BufferedReader input = null;
            try {
                fIn = Config.getInstance().getContext().getResources().getAssets().open(filePath);
                isr = new InputStreamReader(fIn);
                input = new BufferedReader(isr);
                String line;
                while ((line = input.readLine()) != null)
                    returnString.append(line);
            } catch (Exception e) {
                e.printStackTrace();
                return Observable.error(e);
            } finally {
                if (isr != null)
                    try {
                        isr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                if (fIn != null)
                    try {
                        fIn.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                if (input != null)
                    try {
                        input.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
            return Observable.just(returnString.toString());
        });
    }

    @Override
    public Observable<String> readFromFile(String fullFilePath) {
        try {
            return Observable.just(new Gson().fromJson(new InputStreamReader(Config.getInstance()
{'fraction_non_alphanumeric': 0.09504550050556117, 'fraction_numerical': 0.0024266936299292214, 'mean_word_length': 1.5547520661157024, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6444727', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1167, 'n_words': 272}