X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FTemporaryImage.java;h=d5c540cd39d332eeb906f1839ab667d6b4d33596;hb=d39e39ed52c231bd7331c4b2da8e55ffbed081f5;hp=ddac505a576d23f215b02f2ad8e37047034154d2;hpb=4f92a116596bf5d42c5b8beadb5df2bc8149e809;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java b/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java index ddac505..d5c540c 100644 --- a/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java +++ b/src/main/java/net/pterodactylus/sone/data/TemporaryImage.java @@ -1,5 +1,5 @@ /* - * Sone - TemporaryImage.java - Copyright © 2011 David Roden + * Sone - TemporaryImage.java - Copyright © 2011–2013 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 @@ -17,9 +17,9 @@ package net.pterodactylus.sone.data; -import java.util.UUID; +import static com.google.common.base.Preconditions.checkNotNull; -import net.pterodactylus.util.validation.Validation; +import java.util.UUID; /** * A temporary image stores an uploaded image in memory until it has been @@ -33,26 +33,26 @@ public class TemporaryImage { private final String id; /** The MIME type of the image. */ - private String mimeType; + private final String mimeType; /** The encoded image data. */ - private byte[] imageData; + private final byte[] imageData; - /** - * Creates a new temporary image with a random ID. - */ - public TemporaryImage() { - this(UUID.randomUUID().toString()); - } + private final int width; + + private final int height; /** - * Creates a new temporary image. - * - * @param id - * The ID of the temporary image + * Creates a new temporary image with a random ID. + * @param imageData + * @param mimeType */ - public TemporaryImage(String id) { - this.id = id; + public TemporaryImage(String mimeType, byte[] imageData, int width, int height) { + this.id = UUID.randomUUID().toString(); + this.mimeType = checkNotNull(mimeType, "mime type must not be null"); + this.imageData = checkNotNull(imageData, "image data must not be null"); + this.width = width; + this.height = height; } /** @@ -74,20 +74,6 @@ public class TemporaryImage { } /** - * 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 @@ -96,18 +82,12 @@ public class TemporaryImage { 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; + public int getWidth() { + return width; + } + + public int getHeight() { + return height; } }