package io.github.droidkaigi.confsched2017.view.helper;

import android.content.Context;
import android.support.annotation.StringRes;

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

import javax.inject.Inject;
import javax.inject.Singleton;

import timber.log.Timber;

@Singleton
public class ResourceResolver {

    private static final String TAG = ResourceResolver.class.getSimpleName();

    private final Context context;

    @Inject
    public ResourceResolver(Context context) {
        this.context = context;
    }

    public String getString(@StringRes int resId) {
        return context.getString(resId);
    }

    public String getString(@StringRes int resId, Object... formatArgs) {
        return context.getString(resId, formatArgs);
    }

    public String loadJSONFromAsset(final String jsonFileName) {
        String json = null;
        try {
            InputStream is = context.getAssets().open("json/" + jsonFileName);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (IOException e) {
            Timber.e(TAG, e.getMessage(), e);
        }
        return json;
    }
}

@@ -856,16 +856,47 @@
 = null;%0A
+        InputStream is = null;%0A
         
@@ -909,36 +909,24 @@
             
-InputStream 
 is = context
@@ -1084,32 +1084,8 @@
 r);%0A
-            is.close();%0A
     
@@ -1158,24 +1158,24 @@
 eption e) %7B%0A
-
             
@@ -1204,24 +1204,248 @@
 sage(), e);%0A
+        %7D finally %7B%0A            try %7B%0A                if (is != null) %7B%0A                    is.close();%0A                %7D%0A            %7D catch (IOException e) %7B%0A                Timber.e(TAG, e.getMessage(), e);%0A            %7D%0A
         %7D%0A  

Fix try-catch block