View Javadoc
1   /*
2    * Copyright 2013 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.codec.http;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.Unpooled;
20  import io.netty.handler.codec.DecoderResult;
21  
22  
23  final class ComposedLastHttpContent implements LastHttpContent {
24      private final HttpHeaders trailingHeaders;
25      private DecoderResult result;
26  
27      ComposedLastHttpContent(HttpHeaders trailingHeaders) {
28          this.trailingHeaders = trailingHeaders;
29      }
30  
31      @Override
32      public HttpHeaders trailingHeaders() {
33          return trailingHeaders;
34      }
35  
36      @Override
37      public LastHttpContent copy() {
38          LastHttpContent content = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER);
39          content.trailingHeaders().set(trailingHeaders());
40          return content;
41      }
42  
43      @Override
44      public LastHttpContent duplicate() {
45          return copy();
46      }
47  
48      @Override
49      public LastHttpContent retainedDuplicate() {
50          return copy();
51      }
52  
53      @Override
54      public LastHttpContent replace(ByteBuf content) {
55          final LastHttpContent dup = new DefaultLastHttpContent(content);
56          dup.trailingHeaders().setAll(trailingHeaders());
57          return dup;
58      }
59  
60      @Override
61      public LastHttpContent retain(int increment) {
62          return this;
63      }
64  
65      @Override
66      public LastHttpContent retain() {
67          return this;
68      }
69  
70      @Override
71      public LastHttpContent touch() {
72          return this;
73      }
74  
75      @Override
76      public LastHttpContent touch(Object hint) {
77          return this;
78      }
79  
80      @Override
81      public ByteBuf content() {
82          return Unpooled.EMPTY_BUFFER;
83      }
84  
85      @Override
86      public DecoderResult decoderResult() {
87          return result;
88      }
89  
90      @Override
91      public DecoderResult getDecoderResult() {
92          return decoderResult();
93      }
94  
95      @Override
96      public void setDecoderResult(DecoderResult result) {
97          this.result = result;
98      }
99  
100     @Override
101     public int refCnt() {
102         return 1;
103     }
104 
105     @Override
106     public boolean release() {
107         return false;
108     }
109 
110     @Override
111     public boolean release(int decrement) {
112         return false;
113     }
114 }