use of android.util.Base64InputStream in project ig-json-parser by Instagram.
the class BenchmarkActivity method loadFromFile.
private String loadFromFile(int resourceId) throws IOException {
InputStreamReader inputStreamReader = null;
try {
// we're doing this absurd thing with encoding the json file in base64 because phabricator
// chokes on it otherwise.
inputStreamReader = new InputStreamReader(new Base64InputStream(getResources().openRawResource(resourceId), Base64.DEFAULT), "UTF-8");
StringBuilder sb = new StringBuilder();
char[] buffer = new char[8 * 1024];
int bytesRead;
while ((bytesRead = inputStreamReader.read(buffer)) != -1) {
sb.append(buffer, 0, bytesRead);
}
return sb.toString();
} finally {
try {
if (inputStreamReader != null) {
inputStreamReader.close();
}
} catch (IOException ignored) {
//ignored
}
}
}
use of android.util.Base64InputStream in project ocreader by schaal.
the class ListActivity method updateUserProfile.
private void updateUserProfile() {
final String username = Preferences.USERNAME.getString(PreferenceManager.getDefaultSharedPreferences(this));
if (username != null) {
final User user = getRealm().where(User.class).equalTo(User.USER_ID, username).findFirst();
if (user != null) {
profileDrawerItem.withName(user.getDisplayName());
final String encodedImage = user.getAvatar();
if (encodedImage != null) {
Bitmap avatarBitmap = BitmapFactory.decodeStream(new Base64InputStream(new ByteArrayInputStream(encodedImage.getBytes()), Base64.DEFAULT));
profileDrawerItem.withIcon(avatarBitmap);
} else {
profileDrawerItem.withIcon(R.mipmap.ic_launcher);
}
if (accountHeader != null)
accountHeader.updateProfile(profileDrawerItem);
} else {
profileDrawerItem.withIcon(R.mipmap.ic_launcher);
}
} else {
profileDrawerItem.withIcon(R.mipmap.ic_launcher);
}
}
Aggregations