View Javadoc

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 org.jboss.netty.buffer.ChannelBuffer;
19  
20  import java.io.File;
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.nio.charset.Charset;
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      * @return a ChannelBuffer for the content from the current position or an
109      *         EMPTY_BUFFER if there is no more data to return
110      */
111     ChannelBuffer getChunk(int length) throws IOException;
112 
113     /**
114      * Returns the contents of the file item as a String, using the default
115      * character encoding.
116      *
117      * @return the contents of the file item as a String, using the default
118      *         character encoding.
119      */
120     String getString() throws IOException;
121 
122     /**
123      * Returns the contents of the file item as a String, using the specified
124      * charset.
125      *
126      * @param encoding
127      *            the charset to use
128      * @return the contents of the file item as a String, using the specified
129      *         charset.
130      * @exception IOException
131      */
132     String getString(Charset encoding) throws IOException;
133 
134     /**
135      * Set the Charset passed by the browser if defined
136      *
137      * @param charset
138      *            Charset to set - must be not null
139      */
140     void setCharset(Charset charset);
141 
142     /**
143      * Returns the Charset passed by the browser or null if not defined.
144      *
145      * @return the Charset passed by the browser or null if not defined.
146      */
147     Charset getCharset();
148 
149     /**
150      * A convenience method to write an uploaded item to disk. If a previous one
151      * exists, it will be deleted. Once this method is called, if successful,
152      * the new file will be out of the cleaner of the factory that creates the
153      * original InterfaceHttpData object.
154      *
155      * @param dest
156      *            destination file - must be not null
157      * @return True if the write is successful
158      * @exception IOException
159      */
160     boolean renameTo(File dest) throws IOException;
161 
162     /**
163      * Provides a hint as to whether or not the file contents will be read from
164      * memory.
165      *
166      * @return True if the file contents is in memory.
167      */
168     boolean isInMemory();
169 
170     /**
171      *
172      * @return the associated File if this data is represented in a file
173      * @exception IOException
174      *                if this data is not represented by a file
175      */
176     File getFile() throws IOException;
177 
178 }