From dbac2600517cb3292ab6b3379c5c29ec4906bbc3 Mon Sep 17 00:00:00 2001 From: Daniel Henninger Date: Wed, 28 Nov 2007 02:55:32 +0000 Subject: [PATCH] Added ability to set mime type of avatar. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@9526 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smackx/packet/VCard.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/org/jivesoftware/smackx/packet/VCard.java b/source/org/jivesoftware/smackx/packet/VCard.java index a05842406..7c4234a61 100644 --- a/source/org/jivesoftware/smackx/packet/VCard.java +++ b/source/org/jivesoftware/smackx/packet/VCard.java @@ -355,6 +355,26 @@ public class VCard extends IQ { setField("PHOTO", "image/jpeg" + encodedImage + "", true); } + /** + * Specify the bytes for the avatar to use as well as the mime type. + * + * @param bytes the bytes of the avatar. + * @param mimeType the mime type of the avatar. + */ + public void setAvatar(byte[] bytes, String mimeType) { + if (bytes == null) { + // Remove avatar (if any) from mappings + otherUnescapableFields.remove("PHOTO"); + return; + } + + // Otherwise, add to mappings. + String encodedImage = StringUtils.encodeBase64(bytes); + avatar = encodedImage; + + setField("PHOTO", "" + mimeType + "" + encodedImage + "", true); + } + /** * Set the encoded avatar string. This is used by the provider. *