package link.standen.michael.fatesheets.util;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import com.google.gson.Gson;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import link.standen.michael.fatesheets.R;
import link.standen.michael.fatesheets.model.CoreCharacter;
import link.standen.michael.fatesheets.model.FAECharacter;

/**
 * A helper class for managing JSON files
 */
public abstract class JsonFileHelper {

	private static final String TAG = JsonFileHelper.class.getName();

	/**
	 * Saves JSON to a file.
	 * @return True if the write was successful, false otherwise.
	 */
	protected static boolean saveJsonToFile(Context context, String json, String filename) {
		try {
			FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
			fos.write(json.getBytes());
			fos.flush();
			fos.close();
			return true;
		} catch (IOException e) {
			Log.e(TAG, "Error writing JSON", e);
		}
		return false;
	}

	/**
	 * Loads JSON from a file.
	 */
	@Nullable
	public static String getJsonFromFile(Context context, String filename){
		String json = null;

		try {
			FileInputStream fis = context.openFileInput(filename);

			StringBuffer stringBuff = new StringBuffer("");
			byte[] buff = new byte[1024];
			int n;
			while ((n = fis.read(buff)) != -1) {
				stringBuff.append(new String(buff, 0, n));
			}
			fis.close();

			json = stringBuff.toString();
		} catch (FileNotFoundException e) {
			Log.e(TAG, String.format("JSON file %s not found", filename), e);
		} catch (IOException e) {
			Log.e(TAG, String.format("Error reading file %s", filename), e);
		}

		return json;
	}

	/**
	 * Deletes a file.
	 * @return True if the delete was successful, false otherwise.
	 */
	protected static boolean deleteFile(Context context, String filename) {
		return context.deleteFile(filename);
	}

}

@@ -76,51 +76,8 @@
 xt;%0A
-import android.support.annotation.NonNull;%0A
 impo
@@ -146,38 +146,8 @@
 g;%0A%0A
-import com.google.gson.Gson;%0A%0A
 impo
@@ -276,221 +276,8 @@
 ion;
-%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport link.standen.michael.fatesheets.R;%0Aimport link.standen.michael.fatesheets.model.CoreCharacter;%0Aimport link.standen.michael.fatesheets.model.FAECharacter;
 %0A%0A/*
@@ -933,21 +933,24 @@
 lable%0A%09p
-ublic
+rotected
  static 
@@ -1112,23 +1112,17 @@
 ngBu
-ffer stringBuff
+ilder bob
  = n
@@ -1132,18 +1132,19 @@
 StringBu
-ff
+ild
 er(%22%22);%0A
@@ -1230,26 +1230,19 @@
 ) %7B%0A%09%09%09%09
-stringBuff
+bob
 .append(
@@ -1302,18 +1302,11 @@
 n = 
-stringBuff
+bob
 .toS

Refactor JsonFileHelper. Remove unused imports. Change buffer class