From 7e4791c4f627755fde2d42cbe67399e423e43cf2 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 31 Aug 2019 17:07:33 +0200 Subject: [PATCH] Add publish methods without size --- .../smackx/avatar/UserAvatarManager.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/UserAvatarManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/UserAvatarManager.java index 8a59f8557..03b22501f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/UserAvatarManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/UserAvatarManager.java @@ -203,6 +203,24 @@ public final class UserAvatarManager extends Manager { return pepManager.getPepPubSubManager().getOrCreateLeafNode(METADATA_NAMESPACE); } + /** + * Publish a PNG avatar and its metadata to PubSub. + * If you know what the dimensions of the image are, use {@link #publishPNGAvatar(byte[], int, int)} instead. + * + * @param data raw bytes of the avatar + * + * @throws XMPPErrorException if a protocol level error occurs + * @throws PubSubException.NotALeafNodeException if either the metadata node or the data node is not a + * {@link LeafNode} + * @throws NotConnectedException if the connection is not connected + * @throws InterruptedException if the thread is interrupted + * @throws NoResponseException if the server does not respond + */ + public void publishPNGAvatar(byte[] data) throws XMPPErrorException, PubSubException.NotALeafNodeException, + NotConnectedException, InterruptedException, NoResponseException { + publishPNGAvatar(data, 0, 0); + } + /** * Publish a PNG Avatar and its metadata to PubSub. * @@ -224,6 +242,25 @@ public final class UserAvatarManager extends Manager { publishPNGAvatarMetadata(id, data.length, height, width); } + /** + * Publish a PNG avatar and its metadata to PubSub. + * If you know the dimensions of the image, use {@link #publishPNGAvatar(File, int, int)} instead. + * + * @param pngFile PNG File + * + * @throws IOException if an {@link IOException} occurs while reading the file + * @throws XMPPErrorException if a protocol level error occurs + * @throws PubSubException.NotALeafNodeException if either the metadata node or the data node is not a valid + * {@link LeafNode} + * @throws NotConnectedException if the connection is not connected + * @throws InterruptedException if the thread is interrupted + * @throws NoResponseException if the server does not respond + */ + public void publishPNGAvatar(File pngFile) throws NotConnectedException, InterruptedException, + PubSubException.NotALeafNodeException, NoResponseException, IOException, XMPPErrorException { + publishPNGAvatar(pngFile, 0, 0); + } + /** * Publish a PNG avatar and its metadata to PubSub. * @@ -298,7 +335,8 @@ public final class UserAvatarManager extends Manager { } private String publishPNGAvatarData(byte[] data) - throws NoResponseException, NotConnectedException, XMPPErrorException, InterruptedException, PubSubException.NotALeafNodeException { + throws NoResponseException, NotConnectedException, XMPPErrorException, InterruptedException, + PubSubException.NotALeafNodeException { String itemId = Base64.encodeToString(SHA1.bytes(data)); publishAvatarData(data, itemId); return itemId;