| 1 |
|
package com.smartwerkz.jupload.classic.image; |
| 2 |
|
|
| 3 |
|
import java.awt.image.BufferedImage; |
| 4 |
|
import java.io.ByteArrayInputStream; |
| 5 |
|
import java.io.IOException; |
| 6 |
|
import java.io.InputStream; |
| 7 |
|
|
| 8 |
|
import javax.imageio.metadata.IIOMetadata; |
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
public class ImageData { |
| 17 |
|
protected BufferedImage img; |
| 18 |
|
protected IIOMetadata metadata; |
| 19 |
|
protected byte[] bytes; |
| 20 |
|
protected long creationTime; |
| 21 |
|
protected int length; |
| 22 |
0 |
|
| 23 |
0 |
public ImageData(BufferedImage img, IIOMetadata metadata, byte[] rawdata) { |
| 24 |
0 |
length = -1; |
| 25 |
0 |
this.img = img; |
| 26 |
0 |
this.metadata = metadata; |
| 27 |
0 |
setBytes(rawdata); |
| 28 |
0 |
creationTime = System.currentTimeMillis(); |
| 29 |
0 |
} |
| 30 |
|
|
| 31 |
0 |
public ImageData(ImageData data, byte[] rawdata) { |
| 32 |
0 |
this(data.getImage(), data.getMetadata(), rawdata); |
| 33 |
0 |
} |
| 34 |
|
|
| 35 |
0 |
public ImageData(BufferedImage img) { |
| 36 |
0 |
this(img, null, null); |
| 37 |
0 |
} |
| 38 |
|
|
| 39 |
0 |
public void setImage(BufferedImage img) { |
| 40 |
0 |
length = -1; |
| 41 |
0 |
this.img = img; |
| 42 |
0 |
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
0 |
public BufferedImage getImage() { |
| 48 |
0 |
return img; |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
0 |
public void flush() { |
| 55 |
0 |
img.flush(); |
| 56 |
0 |
img = null; |
| 57 |
0 |
bytes = null; |
| 58 |
0 |
} |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
0 |
public IIOMetadata getMetadata() { |
| 64 |
0 |
return metadata; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
0 |
public long getCreationTime() { |
| 68 |
0 |
return creationTime; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
0 |
public byte[] getBytes() { |
| 75 |
0 |
return bytes; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
0 |
public boolean lengthUnknown() { |
| 79 |
0 |
return length == -1; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
0 |
public boolean wasCached() { |
| 83 |
0 |
return length != -1; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
0 |
public int length() { |
| 90 |
0 |
return length; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
0 |
public boolean bytesCached() { |
| 94 |
0 |
return bytes != null; |
| 95 |
|
} |
| 96 |
|
|
| 97 |
0 |
protected void setBytes(byte[] bytes) { |
| 98 |
0 |
this.bytes = bytes; |
| 99 |
0 |
if (bytes != null) |
| 100 |
0 |
length = bytes.length; |
| 101 |
0 |
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
0 |
public InputStream createInputStream() throws IOException { |
| 107 |
0 |
return new ByteArrayInputStream(bytes); |
| 108 |
|
} |
| 109 |
|
} |