diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-04-11 22:20:32 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-04-11 22:20:32 +0200 |
commit | 7ff890e513212f1cf03667e4ea7e429431d811c4 (patch) | |
tree | 779360a59b84b9d7ab7f33fa63b5c098d3fc9aff /src/main/java/eu/siacs/conversations/persistance | |
parent | 23a0beab43a5f30baf6481afeb9188b86df0b32d (diff) |
republish avatar if server offers non-persistent pep :-(
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 0861a3a86..0d770fef6 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.File; import java.io.FileDescriptor; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -402,6 +403,43 @@ public class FileBackend { } } + public Avatar getStoredPepAvatar(String hash) { + if (hash == null) { + return null; + } + Avatar avatar = new Avatar(); + File file = new File(getAvatarPath(hash)); + FileInputStream is = null; + try { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeFile(file.getAbsolutePath(), options); + is = new FileInputStream(file); + ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream(); + Base64OutputStream mBase64OutputStream = new Base64OutputStream(mByteArrayOutputStream, Base64.DEFAULT); + MessageDigest digest = MessageDigest.getInstance("SHA-1"); + DigestOutputStream os = new DigestOutputStream(mBase64OutputStream, digest); + byte[] buffer = new byte[4096]; + int length; + while ((length = is.read(buffer)) > 0) { + os.write(buffer, 0, length); + } + os.flush(); + os.close(); + avatar.sha1sum = CryptoHelper.bytesToHex(digest.digest()); + avatar.image = new String(mByteArrayOutputStream.toByteArray()); + avatar.height = options.outHeight; + avatar.width = options.outWidth; + return avatar; + } catch (IOException e) { + return null; + } catch (NoSuchAlgorithmException e) { + return null; + } finally { + close(is); + } + } + public boolean isAvatarCached(Avatar avatar) { File file = new File(getAvatarPath(avatar.getFilename())); return file.exists(); |