01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.impl;
17:
18: import java.awt.image.BufferedImage;
19: import java.io.IOException;
20: import java.io.OutputStream;
21:
22: import javax.imageio.ImageIO;
23:
24: /**
25: * A way to convert {@link BufferedImage}s to files so they can be written
26: * using a FileServingServlet or similar.
27: * @author Joe Walker [joe at getahead dot ltd dot uk]
28: */
29: public class ImageIOFileGenerator extends AbstractFileGenerator {
30: /**
31: * Setup the image to convert
32: * @param image the image to convert
33: * @param mimeType The mime type to convert the image into
34: * @param type {@link ImageIO} type
35: */
36: public ImageIOFileGenerator(BufferedImage image, String mimeType,
37: String basename, String type) {
38: super (basename + "." + type, mimeType);
39: this .image = image;
40: this .type = type;
41: }
42:
43: /* (non-Javadoc)
44: * @see org.directwebremoting.extend.DownloadManager.FileGenerator#generateFile(java.io.OutputStream)
45: */
46: public void generateFile(OutputStream out) throws IOException {
47: ImageIO.write(image, type, out);
48: }
49:
50: /**
51: * The extension for the filename to go with the mime-type
52: */
53: protected String type;
54:
55: /**
56: * The image that we are about to export
57: */
58: protected final BufferedImage image;
59: }
|