1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-10 18:15:58 +01:00

Fix base64 encoder for avatars.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3021 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro 2005-11-02 04:09:40 +00:00 committed by derek
parent d67b49289b
commit d1924af8c9

View file

@ -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() {