1 package be
.nikiroo
.utils
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
7 * This class represents an image data.
15 * Do not use -- for serialisation purposes only.
17 @SuppressWarnings("unused")
22 * Create a new {@link Image} with the given data.
27 public Image(byte[] data
) {
32 * Create a new {@link Image} from its Base64 representation.
35 * the {@link Image} in Base64 format
38 * in case of I/O error
40 public Image(String base64
) throws IOException
{
41 this(Base64
.decode(base64
));
45 * Create a new {@link Image} from a stream.
51 * in case of I/O error
53 public Image(InputStream in
) throws IOException
{
54 this.data
= IOUtils
.toByteArray(in
);
58 * The actual image data.
60 * This is the actual data, not a copy, so any change made here will be
61 * reflected into the {@link Image} and vice-versa.
63 * @return the image data
65 public byte[] getData() {
70 * Convert the given {@link Image} object into a Base64 representation of
71 * the same {@link Image} object.
73 * @return the Base64 representation
75 public String
toBase64() {
76 return new String(Base64
.encodeBytes(getData()));