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.stream;
17  
18  import org.jboss.netty.buffer.ChannelBuffer;
19  
20  /**
21   * A data stream of indefinite length which is consumed by {@link ChunkedWriteHandler}.
22   *
23   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
24   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
25   * @version $Rev: 2166 $, $Date: 2010-02-18 13:24:41 +0900 (Thu, 18 Feb 2010) $
26   *
27   * @apiviz.landmark
28   */
29  public interface ChunkedInput {
30  
31      /**
32       * Returns {@code true} if and only if there is any data left in the
33       * stream.  Please note that {@code false} does not necessarily mean that
34       * the stream has reached at its end.  In a slow stream, the next chunk
35       * might be unavailable just momentarily.
36       */
37      boolean hasNextChunk() throws Exception;
38  
39      /**
40       * Fetches a chunked data from the stream.  The returned chunk is usually
41       * a {@link ChannelBuffer}, but you could extend an existing implementation
42       * to convert the {@link ChannelBuffer} into a different type that your
43       * handler or encoder understands.  Once this method returns the last chunk
44       * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()}
45       * call must return {@code false}.
46       *
47       * @return the fetched chunk, which is usually {@link ChannelBuffer}.
48       *         {@code null} if there is no data left in the stream.
49       *         Please note that {@code null} does not necessarily mean that the
50       *         stream has reached at its end.  In a slow stream, the next chunk
51       *         might be unavailable just momentarily.
52       */
53      Object nextChunk() throws Exception;
54  
55      /**
56       * Return {@code true} if and only if there is no data left in the stream
57       * and the stream has reached at its end.
58       */
59      boolean isEndOfInput() throws Exception;
60  
61      /**
62       * Releases the resources associated with the stream.
63       */
64      void close() throws Exception;
65  }