01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.resource;
22:
23: import java.awt.image.BufferedImage;
24: import java.io.*;
25: import java.util.logging.Logger;
26: import javax.imageio.ImageIO;
27:
28: public class BufferedImageResource extends AbstractResource {
29: /** the logger **/
30: private static final Logger _logger = Logger
31: .getLogger(BufferedImageResource.class.getName());
32:
33: private File _file;
34:
35: public BufferedImageResource(String id, String type,
36: BufferedImage image) {
37: super (id, type, image);
38: try {
39: File file = File.createTempFile("sw_", ".png");
40: file.deleteOnExit();
41: _file = file;
42: ImageIO.write((BufferedImage) image, "png", file);
43: } catch (IOException e) {
44: _logger.severe("Unable to save temp buffered image - "
45: + e.getMessage());
46: }
47: }
48:
49: public InputStream getInputStream() throws IOException {
50: if (_file != null) {
51: return new FileInputStream(_file);
52: } else {
53: return new ByteArrayInputStream(new byte[0]);
54: }
55: }
56: }
|