Add methods to create and retrieve temporary images.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 10 Apr 2011 18:08:45 +0000 (20:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 04:40:50 +0000 (06:40 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java

index 06a1467..70c0e7e 100644 (file)
@@ -39,6 +39,7 @@ import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Profile.Field;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.freenet.wot.Identity;
 import net.pterodactylus.sone.freenet.wot.IdentityListener;
 import net.pterodactylus.sone.freenet.wot.IdentityManager;
@@ -173,6 +174,9 @@ public class Core implements IdentityListener, UpdateListener {
        /** All known images. */
        private Map<String, Image> images = new HashMap<String, Image>();
 
+       /** All temporary images. */
+       private Map<String, TemporaryImage> temporaryImages = new HashMap<String, TemporaryImage>();
+
        /**
         * Creates a new core.
         *
@@ -799,6 +803,20 @@ public class Core implements IdentityListener, UpdateListener {
                }
        }
 
+       /**
+        * Returns the temporary image with the given ID.
+        *
+        * @param imageId
+        *            The ID of the temporary image
+        * @return The temporary image, or {@code null} if there is no temporary
+        *         image with the given ID
+        */
+       public TemporaryImage getTemporaryImage(String imageId) {
+               synchronized (temporaryImages) {
+                       return temporaryImages.get(imageId);
+               }
+       }
+
        //
        // ACTIONS
        //
@@ -1775,6 +1793,24 @@ public class Core implements IdentityListener, UpdateListener {
        }
 
        /**
+        * Creates a new temporary image.
+        *
+        * @param mimeType
+        *            The MIME type of the temporary image
+        * @param imageData
+        *            The encoded data of the image
+        * @return The temporary image
+        */
+       public TemporaryImage createTemporaryImage(String mimeType, byte[] imageData) {
+               TemporaryImage temporaryImage = new TemporaryImage();
+               temporaryImage.setMimeType(mimeType).setImageData(imageData);
+               synchronized (temporaryImages) {
+                       temporaryImages.put(temporaryImage.getId(), temporaryImage);
+               }
+               return temporaryImage;
+       }
+
+       /**
         * Starts the core.
         */
        public void start() {