Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save talosdev/f1e20b52aefa6fc808ba02c12a5e9599 to your computer and use it in GitHub Desktop.
Save talosdev/f1e20b52aefa6fc808ba02c12a5e9599 to your computer and use it in GitHub Desktop.
package za.co.riggaroo.retrofittestexample;
import android.content.Context;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* @author rebeccafranks
* @since 15/10/24.
*/
public class RestServiceTestHelper {
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
return sb.toString();
}
public static String getStringFromFile(Context context, String filePath) throws Exception {
final InputStream stream = context.getResources().getAssets().open(filePath);
String ret = convertStreamToString(stream);
//Make sure you close all streams.
stream.close();
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment