View Javadoc

1   /*
2    * $Id: FormFile.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.upload;
19  
20  import java.io.FileNotFoundException;
21  import java.io.IOException;
22  import java.io.InputStream;
23  
24  /***
25   * <p> This interface represents a file that has been uploaded by a client. It
26   * is the only interface or class in upload package which is typically
27   * referenced directly by a Struts application. </p>
28   */
29  public interface FormFile {
30      /***
31       * <p> Returns the content type for this file. </p>
32       *
33       * @return A String representing content type.
34       */
35      public String getContentType();
36  
37      /***
38       * <p> Sets the content type for this file. </p>
39       *
40       * @param contentType The content type for the file.
41       */
42      public void setContentType(String contentType);
43  
44      /***
45       * <p> Returns the size of this file. </p>
46       *
47       * @return The size of the file, in bytes.
48       */
49      public int getFileSize();
50  
51      /***
52       * <p> Sets the file size. </p>
53       *
54       * @param fileSize The size of the file, in bytes,
55       */
56      public void setFileSize(int fileSize);
57  
58      /***
59       * <p> Returns the file name of this file. This is the base name of the
60       * file, as supplied by the user when the file was uploaded. </p>
61       *
62       * @return The base file name.
63       */
64      public String getFileName();
65  
66      /***
67       * <p> Sets the file name of this file. </p>
68       *
69       * @param fileName The base file name.
70       */
71      public void setFileName(String fileName);
72  
73      /***
74       * <p> Returns the data for the entire file as byte array. Care is needed
75       * when using this method, since a large upload could easily exhaust
76       * available memory. The preferred method for accessing the file data is
77       * {@link #getInputStream() getInputStream}. </p>
78       *
79       * @return The file data as a byte array.
80       * @throws FileNotFoundException if the uploaded file is not found.
81       * @throws IOException           if an error occurred while reading the
82       *                               file.
83       */
84      public byte[] getFileData()
85          throws FileNotFoundException, IOException;
86  
87      /***
88       * <p> Returns an input stream for this file. The caller must close the
89       * stream when it is no longer needed. </p>
90       *
91       * @throws FileNotFoundException if the uploaded file is not found.
92       * @throws IOException           if an error occurred while reading the
93       *                               file.
94       */
95      public InputStream getInputStream()
96          throws FileNotFoundException, IOException;
97  
98      /***
99       * <p> Destroys all content for the uploaded file, including any
100      * underlying data files. </p>
101      */
102     public void destroy();
103 }