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.io;
17:
18: import java.io.ByteArrayInputStream;
19: import java.io.InputStream;
20:
21: /**
22: * One of the 2 ways you can receive uploaded files from a DWR enabled page is
23: * to expose a method with a {@link FileTransfer} parameter.
24: * The other is to expose a method with an {@link InputStream} parameter.
25: * @author Lance Semmens [uklance at gmail dot com]
26: * @author Joe Walker [joe at getahead dot ltd dot uk]
27: */
28: public class FileTransfer {
29: /**
30: * A ctor for the 3 things browsers tell us about the uploaded file
31: * @param name The remote source filename
32: * @param mimeType The mime type passed in by the browser
33: * @param inputStream A means by which the data can be read
34: */
35: public FileTransfer(String name, String mimeType,
36: InputStream inputStream) {
37: this .name = name;
38: this .mimeType = mimeType;
39: this .inputStream = inputStream;
40: }
41:
42: /**
43: * A ctor for the 3 things browsers tell us about the uploaded file
44: * @param name The remote source filename
45: * @param mimeType The mime type passed in by the browser
46: * @param data The data to be transfered
47: */
48: public FileTransfer(String name, String mimeType, byte[] data) {
49: this .name = name;
50: this .mimeType = mimeType;
51: this .inputStream = new ByteArrayInputStream(data);
52: }
53:
54: /**
55: * Returns the content type passed by the browser or null if not defined.
56: * @return The content type passed by the browser or null if not defined.
57: */
58: public String getMimeType() {
59: return mimeType;
60: }
61:
62: /**
63: * Returns an InputStream that can be used to retrieve the contents of the file.
64: * @return An InputStream that can be used to retrieve the contents of the file.
65: */
66: public InputStream getInputStream() {
67: return inputStream;
68: }
69:
70: /**
71: * Returns the original filename in the client's file-system, as provided by
72: * the browser (or other client software).
73: * In most cases, this will be the base file name, without path information.
74: * However, some clients, such as the Opera browser, do include path
75: * information.
76: * @return The original filename in the client's file-system.
77: */
78: public String getName() {
79: return name;
80: }
81:
82: /**
83: * The remote source filename
84: */
85: private String name;
86:
87: /**
88: * The mime type passed in by the browser
89: */
90: private String mimeType;
91:
92: /**
93: * A means by which the data can be read
94: */
95: private InputStream inputStream;
96: }
|