View Javadoc

1   /*
2    * Copyright 2009 Red Hat, Inc.
3    *
4    * Red Hat licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the
6    * 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.http2;
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   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
28   * @author Andy Taylor (andy.taylor@jboss.org)
29   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
30   * @author <a href="http://openr66.free.fr/">Frederic Bregier</a>
31   *
32   */
33  public interface HttpData extends InterfaceHttpData {
34      /**
35       * Set the content from the ChannelBuffer (erase any previous data)
36       * @param buffer must be not null
37       * @exception IOException
38       */
39      public void setContent(ChannelBuffer buffer) throws IOException;
40  
41      /**
42       * Add the content from the ChannelBuffer
43       * @param buffer must be not null except if last is set to False
44       * @param last True of the buffer is the last one
45       * @exception IOException
46       */
47      public void addContent(ChannelBuffer buffer, boolean last)
48              throws IOException;
49  
50      /**
51       * Set the content from the file (erase any previous data)
52       * @param file must be not null
53       * @exception IOException
54       */
55      public void setContent(File file) throws IOException;
56  
57      /**
58       * Set the content from the inputStream (erase any previous data)
59       * @param inputStream must be not null
60       * @exception IOException
61       */
62      public void setContent(InputStream inputStream) throws IOException;
63  
64      /**
65       *
66       * @return True if the InterfaceHttpData is completed (all data are stored)
67       */
68      public boolean isCompleted();
69  
70      /**
71       * Returns the size in byte of the InterfaceHttpData
72       * @return the size of the InterfaceHttpData
73       */
74      public long length();
75  
76      /**
77       * Deletes the underlying storage for a file item,
78       * including deleting any associated temporary disk file.
79       */
80      public void delete();
81  
82      /**
83       * Returns the contents of the file item as an array of bytes.
84       * @return the contents of the file item as an array of bytes.
85       * @exception IOException
86       */
87      public byte[] get() throws IOException;
88  
89      /**
90       * Returns the content of the file item as a ChannelBuffer
91       * @return the content of the file item as a ChannelBuffer
92       * @throws IOException
93       */
94      public ChannelBuffer getChannelBuffer() throws IOException;
95  
96      /**
97       * Returns a ChannelBuffer for the content from the current position with at most length read
98       * bytes, increasing the current position of the Bytes read. Once it arrives at the end,
99       * it returns an EMPTY_BUFFER and it resets the current position to 0.
100      * @param length
101      * @return a ChannelBuffer for the content from the current position or
102      * an EMPTY_BUFFER if there is no more data to return
103      * @throws IOException
104      */
105     public ChannelBuffer getChunk(int length) throws IOException;
106 
107     /**
108      * Returns the contents of the file item as a String, using the default character encoding.
109      * @return the contents of the file item as a String, using the default character encoding.
110      * @exception IOException
111      */
112     public String getString() throws IOException;
113 
114     /**
115      * Returns the contents of the file item as a String, using the specified charset.
116      * @param encoding the charset to use
117      * @return the contents of the file item as a String, using the specified charset.
118      * @exception IOException
119      */
120     public String getString(Charset encoding) throws IOException;
121 
122     /**
123      * Set the Charset passed by the browser if defined
124      * @param charset Charset to set - must be not null
125      */
126     public void setCharset(Charset charset);
127 
128     /**
129      * Returns the Charset passed by the browser or null if not defined.
130      * @return the Charset passed by the browser or null if not defined.
131      */
132     public Charset getCharset();
133 
134     /**
135      * A convenience method to write an uploaded item to disk.
136      * If a previous one exists, it will be deleted.
137      * Once this method is called, if successful, the new file will be out of the cleaner
138      * of the factory that creates the original InterfaceHttpData object.
139      * @param dest destination file - must be not null
140      * @return True if the write is successful
141      * @exception IOException
142      */
143     public boolean renameTo(File dest) throws IOException;
144 
145     /**
146      * Provides a hint as to whether or not the file contents will be read from memory.
147      * @return True if the file contents is in memory.
148      */
149     public boolean isInMemory();
150 
151     /**
152      *
153      * @return the associated File if this data is represented in a file
154      * @exception IOException if this data is not represented by a file
155      */
156     public File getFile() throws IOException;
157 
158 }