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.InputStream;
21: import java.io.OutputStream;
22:
23: /**
24: * A way to convert {@link BufferedImage}s to files so they can be written
25: * using a FileServingServlet or similar.
26: * @author Joe Walker [joe at getahead dot ltd dot uk]
27: */
28: public class InputStreamFileGenerator extends AbstractFileGenerator {
29: /**
30: * Setup the image to convert
31: * @param in the data to stream
32: * @param mimeType The mime type to convert the image into
33: */
34: public InputStreamFileGenerator(InputStream in, String filename,
35: String mimeType) {
36: super (filename, mimeType);
37: this .in = in;
38: }
39:
40: /* (non-Javadoc)
41: * @see org.directwebremoting.extend.DownloadManager.FileGenerator#generateFile(java.io.OutputStream)
42: */
43: public void generateFile(OutputStream out) throws IOException {
44: byte[] buffer = new byte[1024];
45: while (true) {
46: int length = in.read(buffer);
47: if (length == -1) {
48: break;
49: }
50: out.write(buffer, 0, length);
51: }
52: }
53:
54: /**
55: * The stream that we are about to export
56: */
57: protected final InputStream in;
58: }
|