Mercurial > hg > digilib-old
comparison common/src/main/java/digilib/image/ImageInfoDocuImage.java @ 903:7779b37d1d05
refactored into maven modules per servlet type.
can build servlet-api 2.3 and 3.0 via profile now!
author | robcast |
---|---|
date | Tue, 26 Apr 2011 20:24:31 +0200 |
parents | servlet/src/main/java/digilib/image/ImageInfoDocuImage.java@6e15201cdce9 |
children | 6853c02b238b |
comparison
equal
deleted
inserted
replaced
902:89ba3ffcf552 | 903:7779b37d1d05 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package digilib.image; | |
5 | |
6 import java.io.IOException; | |
7 import java.io.RandomAccessFile; | |
8 | |
9 import org.devlib.schmidt.imageinfo.ImageInfo; | |
10 | |
11 import digilib.io.ImageInput; | |
12 import digilib.util.ImageSize; | |
13 | |
14 /** Simple abstract implementation of the <code>DocuImage</code> interface. | |
15 * Implements only the identify method using the ImageInfo class. | |
16 * @author casties | |
17 * | |
18 */ | |
19 public abstract class ImageInfoDocuImage extends DocuImageImpl { | |
20 | |
21 /* Check image size and type and store in ImageFile f */ | |
22 public ImageInput identify(ImageInput ii) throws IOException { | |
23 logger.debug("identifying (ImageInfo) " + ii); | |
24 RandomAccessFile raf = null; | |
25 try { | |
26 // set up ImageInfo object | |
27 ImageInfo iif = new ImageInfo(); | |
28 if (ii.hasImageInputStream()) { | |
29 iif.setInput(ii.getImageInputStream()); | |
30 } else if (ii.hasFile()) { | |
31 raf = new RandomAccessFile(ii.getFile(), "r"); | |
32 iif.setInput(raf); | |
33 } else { | |
34 return null; | |
35 } | |
36 iif.setCollectComments(false); | |
37 iif.setDetermineImageNumber(false); | |
38 // try with ImageInfo first | |
39 if (iif.check()) { | |
40 ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight()); | |
41 ii.setSize(d); | |
42 ii.setMimetype(iif.getMimeType()); | |
43 logger.debug("image size: " + ii.getSize()); | |
44 return ii; | |
45 } | |
46 } catch (Exception e) { | |
47 logger.debug("ImageInfoDocuimage unable to identify.", e); | |
48 } finally { | |
49 // close file, don't close stream(?) | |
50 if (raf != null) { | |
51 raf.close(); | |
52 } | |
53 } | |
54 return null; | |
55 } | |
56 | |
57 | |
58 } |