package io.github.droidkaigi.confsched2017.util;


import android.content.Context;

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

import timber.log.Timber;

public final class AssetsUtil {

    private AssetsUtil() {
        // No-op
    }

    /**
     * Loads json string from the assets folder
     *
     * @param context      The calling context
     * @param jsonFileName The file name of the json string
     * @return The JSON string
     */
    public static String loadJSONFromAsset(Context context, 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(AssetsUtil.class.getSimpleName(), e.getMessage(), e);
        }
        return json;
    }
}

@@ -571,16 +571,47 @@
 = null;%0A
+        InputStream is = null;%0A
         
@@ -624,36 +624,24 @@
             
-InputStream 
 is = context
@@ -799,32 +799,8 @@
 r);%0A
-            is.close();%0A
     
@@ -873,24 +873,24 @@
 eption e) %7B%0A
-
             
@@ -951,16 +951,254 @@
 e(), e);
+%0A%0A            try %7B%0A                if (is != null) %7B%0A                    is.close();%0A                %7D%0A            %7D catch (IOException exp) %7B%0A                Timber.e(AssetsUtil.class.getSimpleName(), e.getMessage(), exp);%0A            %7D
 %0A       

Fix InputStream leaks