From d1924af8c9cd601306eaaffc4efd7ab103dd60b1 Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Wed, 2 Nov 2005 04:09:40 +0000 Subject: [PATCH] Fix base64 encoder for avatars. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3021 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smackx/packet/VCard.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/org/jivesoftware/smackx/packet/VCard.java b/source/org/jivesoftware/smackx/packet/VCard.java index 1c8fc3746..0593dcddc 100644 --- a/source/org/jivesoftware/smackx/packet/VCard.java +++ b/source/org/jivesoftware/smackx/packet/VCard.java @@ -29,8 +29,10 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.util.StringUtils; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.URL; @@ -369,19 +371,27 @@ public class VCard extends IQ { * @param url the url to read. */ public static byte[] getBytes(URL url) throws IOException { - InputStream in = url.openStream(); - final byte[] buffer = new byte[4096]; - while (true) { - final int bytesRead = in.read(buffer); - if (bytesRead < 0) { - break; - } + final String path = url.getPath(); + final File file = new File(path); + if (file.exists()) { + return getFileBytes(file); } + + return null; + } + + private static byte[] getFileBytes(File file) throws IOException { + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + int bytes = (int) file.length(); + byte[] buffer = new byte[bytes]; + int readBytes = bis.read(buffer); + bis.close(); return buffer; } /** * Returns the SHA-1 Hash of the Avatar image. + * * @return the SHA-1 Hash of the Avatar image. */ public String getAvatarHash() {