KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > multipart > MultipartFile


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.springframework.web.multipart;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22
23 /**
24  * A representation of an uploaded file received in a multipart request.
25  *
26  * <p>The file contents are either stored in memory or temporarily on disk.
27  * In either case, the user is responsible for copying file contents to a
28  * session-level or persistent store as and if desired. The temporary storages
29  * will be cleared at the end of request processing.
30  *
31  * @author Juergen Hoeller
32  * @author Trevor D. Cook
33  * @since 29.09.2003
34  * @see org.springframework.web.multipart.MultipartHttpServletRequest
35  * @see org.springframework.web.multipart.MultipartResolver
36  */

37 public interface MultipartFile {
38
39     /**
40      * Return the name of the parameter in the multipart form.
41      * @return the name of the parameter (never <code>null</code> or empty)
42      */

43     String JavaDoc getName();
44
45     /**
46      * Return the original filename in the client's filesystem.
47      * <p>This may contain path information depending on the browser used,
48      * but it typically will not with any other than Opera.
49      * @return the original filename, or the empty String if no file
50      * has been chosen in the multipart form
51      */

52     String JavaDoc getOriginalFilename();
53
54     /**
55      * Return the content type of the file.
56      * @return the content type, or <code>null</code> if not defined
57      * (or no file has been chosen in the multipart form)
58      */

59     String JavaDoc getContentType();
60
61     /**
62      * Return whether the uploaded file is empty, that is, either no file has
63      * been chosen in the multipart form or the chosen file has no content.
64      */

65     boolean isEmpty();
66
67     /**
68      * Return the size of the file in bytes.
69      * @return the size of the file, or 0 if empty
70      */

71     long getSize();
72
73     /**
74      * Return the contents of the file as an array of bytes.
75      * @return the contents of the file as bytes, or an empty byte array if empty
76      * @throws IOException in case of access errors (if the temporary store fails)
77      */

78     byte[] getBytes() throws IOException JavaDoc;
79
80     /**
81      * Return an InputStream to read the contents of the file from.
82      * The user is responsible for closing the stream.
83      * @return the contents of the file as stream, or an empty stream if empty
84      * @throws IOException in case of access errors (if the temporary store fails)
85      */

86     InputStream JavaDoc getInputStream() throws IOException JavaDoc;
87
88     /**
89      * Transfer the received file to the given destination file.
90      * <p>This may either move the file in the filesystem, copy the file in the
91      * filesystem, or save memory-held contents to the destination file.
92      * If the destination file already exists, it will be deleted first.
93      * <p>If the file has been moved in the filesystem, this operation cannot
94      * be invoked again. Therefore, call this method just once to be able to
95      * work with any storage mechanism.
96      * @param dest the destination file
97      * @throws IOException in case of reading or writing errors
98      * @throws IllegalStateException if the file has already been moved
99      * in the filesystem and is not available anymore for another transfer
100      */

101     void transferTo(File JavaDoc dest) throws IOException JavaDoc, IllegalStateException JavaDoc;
102
103 }
104
Popular Tags