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.io.ByteArrayOutputStream;
19: import java.io.IOException;
20:
21: import org.directwebremoting.extend.DownloadManager;
22: import org.directwebremoting.extend.FileGenerator;
23: import org.directwebremoting.util.Base64;
24:
25: /**
26: * A download manager that works my returning a data: URL so the data is
27: * sent directly without waiting in some store.
28: * <p>This method has the benefit that it works in a clustered environment
29: * and is quite simple. However it does not work in IE.
30: * @author Jose Noheda [jose dot noheda at gmail dot com]
31: * @author Joe Walker [joe at getahead dot ltd dot uk]
32: */
33: public class DataUrlDownloadManager implements DownloadManager {
34: /* (non-Javadoc)
35: * @see org.directwebremoting.extend.DownloadManager#addFile(org.directwebremoting.extend.DownloadManager.FileGenerator)
36: */
37: public String addFile(FileGenerator generator) throws IOException {
38: ByteArrayOutputStream out = new ByteArrayOutputStream();
39: String mimeType = generator.getMimeType();
40: generator.generateFile(out);
41: String base64data = new String(Base64.encodeBase64(out
42: .toByteArray()));
43: return "'data:" + mimeType + ";base64," + base64data + "'";
44: }
45:
46: /* (non-Javadoc)
47: * @see org.directwebremoting.extend.DownloadManager#getFile(java.lang.String)
48: */
49: public FileGenerator getFile(String id) {
50: throw new UnsupportedOperationException(
51: "data: URLs should not be touched with http:");
52: }
53: }
|