mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 22:12:05 +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:
parent
d67b49289b
commit
d1924af8c9
1 changed files with 18 additions and 8 deletions
|
@ -29,8 +29,10 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -369,19 +371,27 @@ public class VCard extends IQ {
|
||||||
* @param url the url to read.
|
* @param url the url to read.
|
||||||
*/
|
*/
|
||||||
public static byte[] getBytes(URL url) throws IOException {
|
public static byte[] getBytes(URL url) throws IOException {
|
||||||
InputStream in = url.openStream();
|
final String path = url.getPath();
|
||||||
final byte[] buffer = new byte[4096];
|
final File file = new File(path);
|
||||||
while (true) {
|
if (file.exists()) {
|
||||||
final int bytesRead = in.read(buffer);
|
return getFileBytes(file);
|
||||||
if (bytesRead < 0) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the SHA-1 Hash of the Avatar image.
|
* Returns the SHA-1 Hash of the Avatar image.
|
||||||
|
*
|
||||||
* @return the SHA-1 Hash of the Avatar image.
|
* @return the SHA-1 Hash of the Avatar image.
|
||||||
*/
|
*/
|
||||||
public String getAvatarHash() {
|
public String getAvatarHash() {
|
||||||
|
|
Loading…
Reference in a new issue