1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. 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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.model;
20
21 import java.io.InputStream;
22 import java.io.IOException;
23
24 /**
25 * Interface that describes the contents of a single file.
26 *
27 * @see org.apache.myfaces.trinidad.component.core.input.CoreInputFile
28 */
29 public interface UploadedFile
30 {
31 /**
32 * Returns the filename reported by the client.
33 */
34 public String getFilename();
35
36 /**
37 * Returns the MIME type of the file.
38 */
39 public String getContentType();
40
41 /**
42 * Returns the total length (in bytes) of the file.
43 * A length of -1 is interpreted as an error situation, and will be treated as JSF convertor
44 * failure. When this happens, the details of this error is expected to be in the toString()
45 * implementation of the object returned through getOpaqueData(). This detail will be displayed
46 * to the user as a conversion failure message.
47 * @see UploadedFile#getOpaqueData()
48 */
49 public long getLength();
50
51
52 /**
53 * Return opaque data associated with the file when it was
54 * processed by the
55 * {@link org.apache.myfaces.trinidad.webapp.UploadedFileProcessor}.
56 * This is always null with the default <code>UploadedFileProcessor</code>,
57 * but custom implementations may use this to pass additional information
58 * needed for later processing. (Note that Apache Trinidad cannot
59 * cannot guarantee that the instance returned from
60 * code>UploadedFileProcessor</code> is the same one made available
61 * later.
62 * @see UploadedFile#getLength()
63 */
64 public Object getOpaqueData();
65
66 /**
67 * Returns an InputStream that can be used to read the file.
68 * This method can be called repeatedly.
69 */
70 public InputStream getInputStream() throws IOException;
71
72 /**
73 * Disposes all resources allocated for this file.
74 */
75 public void dispose();
76 }