Added getAvatarHash to allow for avatar updates.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2974 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro 2005-10-18 15:43:22 +00:00 committed by derek
parent 78becc3d73
commit df4c1981ba
1 changed files with 25 additions and 0 deletions

View File

@ -34,6 +34,8 @@ import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -309,6 +311,7 @@ public class VCard extends IQ {
/**
* Specify the bytes for the avatar to use.
*
* @param bytes the bytes of the avatar.
*/
public void setAvatar(byte[] bytes) {
@ -377,6 +380,28 @@ public class VCard extends IQ {
return buffer;
}
/**
* Returns the SHA-1 Hash of the Avatar image.
* @return the SHA-1 Hash of the Avatar image.
*/
public String getAvatarHash() {
byte[] bytes = getAvatar();
if (bytes == null) {
return null;
}
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-1");
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
digest.update(bytes);
return StringUtils.encodeHex(digest.digest());
}
/**
* Save this vCard for the user connected by 'connection'. Connection should be authenticated
* and not anonymous.<p>