1 /*
2 * Copyright 2012 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package org.jboss.netty.handler.codec.http.multipart;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.nio.charset.Charset;
22
23 import org.jboss.netty.buffer.ChannelBuffer;
24
25 /**
26 * Extended interface for InterfaceHttpData
27 */
28 public interface HttpData extends InterfaceHttpData {
29 /**
30 * Set the content from the ChannelBuffer (erase any previous data)
31 *
32 * @param buffer
33 * must be not null
34 * @exception IOException
35 */
36 void setContent(ChannelBuffer buffer) throws IOException;
37
38 /**
39 * Add the content from the ChannelBuffer
40 *
41 * @param buffer
42 * must be not null except if last is set to False
43 * @param last
44 * True of the buffer is the last one
45 * @exception IOException
46 */
47 void addContent(ChannelBuffer buffer, boolean last) throws IOException;
48
49 /**
50 * Set the content from the file (erase any previous data)
51 *
52 * @param file
53 * must be not null
54 * @exception IOException
55 */
56 void setContent(File file) throws IOException;
57
58 /**
59 * Set the content from the inputStream (erase any previous data)
60 *
61 * @param inputStream
62 * must be not null
63 * @exception IOException
64 */
65 void setContent(InputStream inputStream) throws IOException;
66
67 /**
68 *
69 * @return True if the InterfaceHttpData is completed (all data are stored)
70 */
71 boolean isCompleted();
72
73 /**
74 * Returns the size in byte of the InterfaceHttpData
75 *
76 * @return the size of the InterfaceHttpData
77 */
78 long length();
79
80 /**
81 * Deletes the underlying storage for a file item, including deleting any
82 * associated temporary disk file.
83 */
84 void delete();
85
86 /**
87 * Returns the contents of the file item as an array of bytes.
88 *
89 * @return the contents of the file item as an array of bytes.
90 * @exception IOException
91 */
92 byte[] get() throws IOException;
93
94 /**
95 * Returns the content of the file item as a ChannelBuffer
96 *
97 * @return the content of the file item as a ChannelBuffer
98 * @throws IOException
99 */
100 ChannelBuffer getChannelBuffer() throws IOException;
101
102 /**
103 * Returns a ChannelBuffer for the content from the current position with at
104 * most length read bytes, increasing the current position of the Bytes
105 * read. Once it arrives at the end, it returns an EMPTY_BUFFER and it
106 * resets the current position to 0.
107 *
108 * @param length
109 * @return a ChannelBuffer for the content from the current position or an
110 * EMPTY_BUFFER if there is no more data to return
111 * @throws IOException
112 */
113 ChannelBuffer getChunk(int length) throws IOException;
114
115 /**
116 * Returns the contents of the file item as a String, using the default
117 * character encoding.
118 *
119 * @return the contents of the file item as a String, using the default
120 * character encoding.
121 * @exception IOException
122 */
123 String getString() throws IOException;
124
125 /**
126 * Returns the contents of the file item as a String, using the specified
127 * charset.
128 *
129 * @param encoding
130 * the charset to use
131 * @return the contents of the file item as a String, using the specified
132 * charset.
133 * @exception IOException
134 */
135 String getString(Charset encoding) throws IOException;
136
137 /**
138 * Set the Charset passed by the browser if defined
139 *
140 * @param charset
141 * Charset to set - must be not null
142 */
143 void setCharset(Charset charset);
144
145 /**
146 * Returns the Charset passed by the browser or null if not defined.
147 *
148 * @return the Charset passed by the browser or null if not defined.
149 */
150 Charset getCharset();
151
152 /**
153 * A convenience method to write an uploaded item to disk. If a previous one
154 * exists, it will be deleted. Once this method is called, if successful,
155 * the new file will be out of the cleaner of the factory that creates the
156 * original InterfaceHttpData object.
157 *
158 * @param dest
159 * destination file - must be not null
160 * @return True if the write is successful
161 * @exception IOException
162 */
163 boolean renameTo(File dest) throws IOException;
164
165 /**
166 * Provides a hint as to whether or not the file contents will be read from
167 * memory.
168 *
169 * @return True if the file contents is in memory.
170 */
171 boolean isInMemory();
172
173 /**
174 *
175 * @return the associated File if this data is represented in a file
176 * @exception IOException
177 * if this data is not represented by a file
178 */
179 File getFile() throws IOException;
180
181 }