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 io.netty.handler.stream;
17  
18  
19  import io.netty.buffer.ByteBufAllocator;
20  import io.netty.channel.ChannelHandlerContext;
21  
22  /**
23   * A data stream of indefinite length which is consumed by {@link ChunkedWriteHandler}.
24   */
25  public interface ChunkedInput<B> {
26  
27      /**
28       * Return {@code true} if and only if there is no data left in the stream
29       * and the stream has reached at its end.
30       */
31      boolean isEndOfInput() throws Exception;
32  
33      /**
34       * Releases the resources associated with the input.
35       */
36      void close() throws Exception;
37  
38      /**
39       * @deprecated Use {@link #readChunk(ByteBufAllocator)}.
40       *
41       * <p>Fetches a chunked data from the stream. Once this method returns the last chunk
42       * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()}
43       * call must return {@code true}.
44       *
45       * @param ctx The context which provides a {@link ByteBufAllocator} if buffer allocation is necessary.
46       * @return the fetched chunk.
47       *         {@code null} if there is no data left in the stream.
48       *         Please note that {@code null} does not necessarily mean that the
49       *         stream has reached at its end.  In a slow stream, the next chunk
50       *         might be unavailable just momentarily.
51       */
52      @Deprecated
53      B readChunk(ChannelHandlerContext ctx) throws Exception;
54  
55      /**
56       * Fetches a chunked data from the stream. Once this method returns the last chunk
57       * and thus the stream has reached at its end, any subsequent {@link #isEndOfInput()}
58       * call must return {@code true}.
59       *
60       * @param allocator {@link ByteBufAllocator} if buffer allocation is necessary.
61       * @return the fetched chunk.
62       *         {@code null} if there is no data left in the stream.
63       *         Please note that {@code null} does not necessarily mean that the
64       *         stream has reached at its end.  In a slow stream, the next chunk
65       *         might be unavailable just momentarily.
66       */
67      B readChunk(ByteBufAllocator allocator) throws Exception;
68  
69      /**
70       * Returns the length of the input.
71       * @return  the length of the input if the length of the input is known.
72       *          a negative value if the length of the input is unknown.
73       */
74      long length();
75  
76      /**
77       * Returns current transfer progress.
78       */
79      long progress();
80  
81  }