Search in sources :

Example 1 with Base64InputStream

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
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Base64InputStream(android.util.Base64InputStream)

Example 2 with Base64InputStream

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) User(email.schaal.ocreader.database.model.User) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(android.util.Base64InputStream)

Aggregations

Base64InputStream (android.util.Base64InputStream)2 Bitmap (android.graphics.Bitmap)1 User (email.schaal.ocreader.database.model.User)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1