From 7689b3967077553c3243585af15f7f9ed4e261c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 10 Apr 2011 20:04:31 +0200 Subject: [PATCH] Add temporary image. --- .../pterodactylus/sone/data/TemporaryImage.java | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/data/TemporaryImage.java diff --git a/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java b/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java new file mode 100644 index 0000000..ddac505 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java @@ -0,0 +1,113 @@ +/* + * Sone - TemporaryImage.java - Copyright © 2011 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.data; + +import java.util.UUID; + +import net.pterodactylus.util.validation.Validation; + +/** + * A temporary image stores an uploaded image in memory until it has been + * inserted into Freenet and is subsequently loaded from there. + * + * @author David ‘Bombe’ Roden + */ +public class TemporaryImage { + + /** The ID of the temporary image. */ + private final String id; + + /** The MIME type of the image. */ + private String mimeType; + + /** The encoded image data. */ + private byte[] imageData; + + /** + * Creates a new temporary image with a random ID. + */ + public TemporaryImage() { + this(UUID.randomUUID().toString()); + } + + /** + * Creates a new temporary image. + * + * @param id + * The ID of the temporary image + */ + public TemporaryImage(String id) { + this.id = id; + } + + /** + * Returns the ID of the temporary image. + * + * @return The ID of the temporary image + */ + public String getId() { + return id; + } + + /** + * Returns the MIME type of the image. + * + * @return The MIME type of the image + */ + public String getMimeType() { + return mimeType; + } + + /** + * Sets the MIME type of the image. The MIME type can only be set once and + * it must not be {@code null}. + * + * @param mimeType + * The MIME type of the image + * @return This temporary image + */ + public TemporaryImage setMimeType(String mimeType) { + Validation.begin().isNotNull("MIME Type", mimeType).isNull("Previous MIME Type", this.mimeType).check(); + this.mimeType = mimeType; + return this; + } + + /** + * Returns the encoded image data. + * + * @return The encoded image data + */ + public byte[] getImageData() { + return imageData; + } + + /** + * Sets the encoded image data. The encoded image data can only be set once + * and it must not be {@code null}. + * + * @param imageData + * The encoded image data + * @return This temporary image + */ + public TemporaryImage setImageData(byte[] imageData) { + Validation.begin().isNotNull("Image Data", imageData).isNull("Previous Image Data", this.imageData).check(); + this.imageData = imageData; + return this; + } + +} -- 2.7.4