1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package io.netty.handler.codec.http2;
16
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.ByteBufAllocator;
19 import io.netty.channel.ChannelHandlerContext;
20 import io.netty.handler.stream.ChunkedInput;
21 import io.netty.util.internal.ObjectUtil;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public final class Http2DataChunkedInput implements ChunkedInput<Http2DataFrame> {
47
48 private final ChunkedInput<ByteBuf> input;
49 private final Http2FrameStream stream;
50 private boolean endStreamSent;
51
52
53
54
55
56
57
58 public Http2DataChunkedInput(ChunkedInput<ByteBuf> input, Http2FrameStream stream) {
59 this.input = ObjectUtil.checkNotNull(input, "input");
60 this.stream = ObjectUtil.checkNotNull(stream, "stream");
61 }
62
63 @Override
64 public boolean isEndOfInput() throws Exception {
65 if (input.isEndOfInput()) {
66
67 return endStreamSent;
68 }
69 return false;
70 }
71
72 @Override
73 public void close() throws Exception {
74 input.close();
75 }
76
77 @Deprecated
78 @Override
79 public Http2DataFrame readChunk(ChannelHandlerContext ctx) throws Exception {
80 return readChunk(ctx.alloc());
81 }
82
83 @Override
84 public Http2DataFrame readChunk(ByteBufAllocator allocator) throws Exception {
85 if (endStreamSent) {
86 return null;
87 }
88
89 if (input.isEndOfInput()) {
90 endStreamSent = true;
91 return new DefaultHttp2DataFrame(true).stream(stream);
92 }
93
94 ByteBuf buf = input.readChunk(allocator);
95 if (buf == null) {
96 return null;
97 }
98
99 final Http2DataFrame dataFrame = new DefaultHttp2DataFrame(buf, input.isEndOfInput()).stream(stream);
100 if (dataFrame.isEndStream()) {
101 endStreamSent = true;
102 }
103
104 return dataFrame;
105 }
106
107 @Override
108 public long length() {
109 return input.length();
110 }
111
112 @Override
113 public long progress() {
114 return input.progress();
115 }
116 }