From 1ac5be485502e7d6d4c117335e083c684739e6af Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 31 Aug 2014 16:28:21 +0200 Subject: some code cleanup --- src/eu/siacs/conversations/xmpp/pep/Avatar.java | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/eu/siacs/conversations/xmpp/pep') diff --git a/src/eu/siacs/conversations/xmpp/pep/Avatar.java b/src/eu/siacs/conversations/xmpp/pep/Avatar.java index 6d5c1431..154fadf6 100644 --- a/src/eu/siacs/conversations/xmpp/pep/Avatar.java +++ b/src/eu/siacs/conversations/xmpp/pep/Avatar.java @@ -11,48 +11,51 @@ public class Avatar { public int width; public long size; public String owner; + public byte[] getImageAsBytes() { return Base64.decode(image, Base64.DEFAULT); } + public String getFilename() { - if (type==null) { + if (type == null) { return sha1sum; } else if (type.equalsIgnoreCase("image/webp")) { - return sha1sum+".webp"; + return sha1sum + ".webp"; } else if (type.equalsIgnoreCase("image/png")) { - return sha1sum+".png"; + return sha1sum + ".png"; } else { return sha1sum; } } - + public static Avatar parseMetadata(Element items) { Element item = items.findChild("item"); - if (item==null) { + if (item == null) { return null; } Element metadata = item.findChild("metadata"); - if (metadata==null) { + if (metadata == null) { return null; } String primaryId = item.getAttribute("id"); - if (primaryId==null) { + if (primaryId == null) { return null; } - for(Element child : metadata.getChildren()) { - if (child.getName().equals("info") && primaryId.equals(child.getAttribute("id"))) { + for (Element child : metadata.getChildren()) { + if (child.getName().equals("info") + && primaryId.equals(child.getAttribute("id"))) { Avatar avatar = new Avatar(); String height = child.getAttribute("height"); String width = child.getAttribute("width"); String size = child.getAttribute("bytes"); try { - if (height!=null) { + if (height != null) { avatar.height = Integer.parseInt(height); } - if (width!=null) { + if (width != null) { avatar.width = Integer.parseInt(width); } - if (size!=null) { + if (size != null) { avatar.size = Long.parseLong(size); } } catch (NumberFormatException e) { -- cgit v1.2.3