01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ImageIOLoader.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.loader.image;
09:
10: import com.uwyn.rife.cmf.dam.exceptions.ContentManagerException;
11: import com.uwyn.rife.cmf.loader.ImageContentLoaderBackend;
12: import com.uwyn.rife.tools.ExceptionUtils;
13: import com.uwyn.rife.tools.ImageWaiter;
14: import java.awt.Image;
15: import java.io.ByteArrayInputStream;
16: import java.util.Set;
17: import javax.imageio.ImageIO;
18:
19: /**
20: * This is an image loader back-end that uses ImageIO to load image files.
21: *
22: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
23: * @version $Revision: 3634 $
24: * @since 1.0
25: */
26: public class ImageIOLoader extends ImageContentLoaderBackend {
27: public Image loadFromBytes(byte[] data, Set<String> errors)
28: throws ContentManagerException {
29: ByteArrayInputStream is = new ByteArrayInputStream(data);
30: Image image = null;
31:
32: try {
33: // create an awt image and wait 'till it's fully loaded
34: image = ImageIO.read(is);
35: ImageWaiter.wait(image);
36: } catch (Throwable e) {
37: if (errors != null) {
38: errors.add(ExceptionUtils.getExceptionStackTrace(e));
39: }
40:
41: image = null;
42: }
43:
44: return image;
45: }
46:
47: public boolean isBackendPresent() {
48: return true;
49: }
50: }
|