01: /**
02: * Copyright 2006 Webmedia Group Ltd.
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: **/package org.araneaframework.uilib.support;
16:
17: import java.io.Serializable;
18: import org.apache.commons.fileupload.FileItem;
19:
20: /**
21: * This file represents a file info received from a {@link org.araneaframework.uilib.form.control.FileUploadControl}. Besides
22: * common file attributes (name, original name, size and type) this class also provides a {@link #readFileContent()} method,
23: * which allows to read the file content as a <code>byte[]</code>
24: *
25: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
26: *
27: */
28: public class FileInfo implements Serializable {
29: private transient FileItem item;
30:
31: public FileInfo(FileItem item) {
32: this .item = item;
33: }
34:
35: /**
36: * Returns the content MIME type.
37: * @return the content MIME type.
38: */
39: public String getContentType() {
40: return item.getContentType();
41: }
42:
43: /**
44: * Returns the original filename (user side).
45: * @return the original filename (user side).
46: */
47: public String getOriginalFilename() {
48: return item.getName();
49: }
50:
51: /**
52: * Returns the file size.
53: * @return the file size.
54: */
55: public long getSize() {
56: return item.getSize();
57: }
58:
59: /**
60: * Returns file content. This method actually reads the content
61: * of the file, not just returns the saved value.
62: *
63: * @return File content.
64: */
65: public byte[] readFileContent() {
66: return item.get();
67: }
68:
69: }
|