powered by Jive Software

Does VCard.getAvatar() really work?

Hello everybody,

I can’‘t correctly get avatars with VCard.getAvatar(). The byte buffer I get seems to be corrupted, even if I write the bytes to the disk I cannot produce a valid image file. The image I’'m using is about 6.2 KB. Any suggestions?

Thanks

Davide

I’‘m trying with smaller pictures, and this is the error I’'m getting with a file of about 3KB and one about 2KB.

Corrupt JPEG data: 1 extraneous bytes before marker 0xfd

Nobody’'s using this feature?

Any help would be really appreciated.

Thanks

D.

Hello people,

I’'ve found a solution.

From my few tests it seems that SMACK clients are able to show avatars created with SMACK, but not them created with other clients.

Looking at VCard’‘s source code I saw that avatar bytes are decoded from a private avatar field. I used this “hack” to get avatar bytes, decoding them with Sun’'s Base64Decoder, and now everything goes fine.

private byte[] getAvatarBytes(VCard vcard){

byte[] res = null;

try{

Field f = VCard.class.getDeclaredField(“avatar”);

f.setAccessible(true);

String avatar = (String)f.get(vcard);

sun.misc.BASE64Decoder enc = new sun.misc.BASE64Decoder();

res = enc.decodeBuffer(avatar);

}catch(Exception e){

e.printStackTrace();

}

return res;

}

Is it a bug or am I using libraries in a wrong way ?

I’‘m not surprised as I’'ve had issues with our Base64 debugger before. There is another Base64 implementation in Smack that I will likely switch this method into using. Could you post the base64 data here so that I can create a test case to confirm that everything is functioning okay?

Thanks,

Alex

Hi Alex, here’‘s the full vCard response which makes getAvatar() method fail. Using Sun’'s Base64Decoder the picture is OK.

Thanks

Davide

/9j/4AAQSkZJRgABAQEASABIAAD/4QAWRXhpZgAATU0AKgAAAAgAAAAAAAD/2wBDAAUDBAQEAwUE

BAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/

2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e

Hh4eHh4eHh4eHh7/wAARCABQAFADASIAAhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAABwgFBgID

BAkB/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ZKKgpaCjtdPDR0YaPhBGgRI1UfKiqOgA

CgADtrKoqPLpKaXPVXUdPtnXTNUBLlTQR4xHlj+gHT/7pjw8oTsf/9k=

Thanks for the info. I found the issue in Smack and checked in a fix for it:

SMACK-135

Cheers,

Alex