Revision 67c1c6d9
Added by Niels Hoffmann over 12 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/ImageInfo.java | ||
---|---|---|
15 | 15 |
import java.util.HashMap; |
16 | 16 |
import java.util.Map; |
17 | 17 |
|
18 |
import org.apache.commons.lang.StringUtils; |
|
18 | 19 |
import org.apache.http.HttpException; |
20 |
import org.apache.http.client.ClientProtocolException; |
|
19 | 21 |
import org.apache.log4j.Logger; |
20 | 22 |
import org.apache.sanselan.ImageReadException; |
21 | 23 |
import org.apache.sanselan.Sanselan; |
... | ... | |
42 | 44 |
|
43 | 45 |
public static ImageInfo NewInstance(URI imageUri, Integer timeOut) throws IOException, HttpException { |
44 | 46 |
ImageInfo instance = new ImageInfo(imageUri); |
47 |
instance.readSuffix(); |
|
48 |
instance.readImageLength(); |
|
45 | 49 |
instance.readImageInfo(timeOut); |
46 | 50 |
return instance; |
47 | 51 |
} |
... | ... | |
81 | 85 |
return getFormatName() + " [" + getMimeType()+ "] w:" + width + " h:" + height + " depth:" + bitPerPixel; |
82 | 86 |
} |
83 | 87 |
|
88 |
private void readSuffix(){ |
|
89 |
String path = imageUri.getPath(); |
|
90 |
|
|
91 |
String suffix = path.substring(StringUtils.lastIndexOf(path, '.') + 1); |
|
92 |
setSuffix(suffix); |
|
93 |
} |
|
94 |
|
|
95 |
private void readImageLength() throws ClientProtocolException, IOException, HttpException{ |
|
96 |
long length = UriUtils.getResourceLength(imageUri, null); |
|
97 |
setLength(length); |
|
98 |
} |
|
99 |
|
|
84 | 100 |
private void readImageInfo(Integer timeOut) throws IOException, HttpException{ |
85 | 101 |
|
86 | 102 |
InputStream inputStream; |
87 | 103 |
try { |
88 |
|
|
89 |
long length = UriUtils.getResourceLength(imageUri, null); |
|
90 |
|
|
91 | 104 |
inputStream = UriUtils.getInputStream(imageUri); |
92 | 105 |
org.apache.sanselan.ImageInfo imageInfo = Sanselan.getImageInfo(inputStream, null); |
93 |
|
|
94 |
setLength(length); |
|
106 |
|
|
95 | 107 |
setFormatName(imageInfo.getFormatName()); |
96 | 108 |
setMimeType(imageInfo.getMimeType()); |
97 | 109 |
width = imageInfo.getWidth(); |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/MediaInfo.java | ||
---|---|---|
23 | 23 |
private String formatName; |
24 | 24 |
private String mimeType; |
25 | 25 |
private long length; |
26 |
private String suffix; |
|
26 | 27 |
|
27 | 28 |
|
28 | 29 |
public void setMimeType(String mimeType) { |
... | ... | |
48 | 49 |
public long getLength() { |
49 | 50 |
return length; |
50 | 51 |
} |
52 |
|
|
53 |
public void setSuffix(String suffix) { |
|
54 |
this.suffix = suffix; |
|
55 |
} |
|
56 |
|
|
57 |
public String getSuffix() { |
|
58 |
return suffix; |
|
59 |
} |
|
51 | 60 |
|
52 | 61 |
} |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/media/ImageInfoTest.java | ||
---|---|---|
191 | 191 |
Assert.assertEquals(9143, getRemotePngInstance().getLength()); |
192 | 192 |
} |
193 | 193 |
} |
194 |
|
|
195 |
@Test |
|
196 |
public void testGetSuffix(){ |
|
197 |
Assert.assertEquals("jpg", getJpegInstance().getSuffix()); |
|
198 |
Assert.assertEquals("tif", getTifInstance().getSuffix()); |
|
199 |
|
|
200 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
201 |
Assert.assertEquals("png", getRemotePngInstance().getSuffix()); |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
|
|
194 | 206 |
|
195 | 207 |
@Test |
196 | 208 |
public void testReadMetaDataJpeg() throws IOException, HttpException{ |
Also available in: Unified diff
ImageInfo now also gathers information about the file suffix