Created
May 26, 2016 14:19
-
-
Save talosdev/f1e20b52aefa6fc808ba02c12a5e9599 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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