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    *   https://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.util.internal.ObjectUtil;
20  import io.netty.util.internal.StringUtil;
21  
22  /**
23   * The default {@link HttpContent} implementation.
24   */
25  public class DefaultHttpContent extends DefaultHttpObject implements HttpContent {
26  
27      private final ByteBuf content;
28  
29      /**
30       * Creates a new instance with the specified chunk content.
31       */
32      public DefaultHttpContent(ByteBuf content) {
33          this.content = ObjectUtil.checkNotNull(content, "content");
34      }
35  
36      @Override
37      public ByteBuf content() {
38          return content;
39      }
40  
41      @Override
42      public HttpContent copy() {
43          return replace(content.copy());
44      }
45  
46      @Override
47      public HttpContent duplicate() {
48          return replace(content.duplicate());
49      }
50  
51      @Override
52      public HttpContent retainedDuplicate() {
53          return replace(content.retainedDuplicate());
54      }
55  
56      @Override
57      public HttpContent replace(ByteBuf content) {
58          return new DefaultHttpContent(content);
59      }
60  
61      @Override
62      public int refCnt() {
63          return content.refCnt();
64      }
65  
66      @Override
67      public HttpContent retain() {
68          content.retain();
69          return this;
70      }
71  
72      @Override
73      public HttpContent retain(int increment) {
74          content.retain(increment);
75          return this;
76      }
77  
78      @Override
79      public HttpContent touch() {
80          content.touch();
81          return this;
82      }
83  
84      @Override
85      public HttpContent touch(Object hint) {
86          content.touch(hint);
87          return this;
88      }
89  
90      @Override
91      public boolean release() {
92          return content.release();
93      }
94  
95      @Override
96      public boolean release(int decrement) {
97          return content.release(decrement);
98      }
99  
100     @Override
101     public String toString() {
102         return StringUtil.simpleClassName(this) +
103                "(data: " + content() + ", decoderResult: " + decoderResult() + ')';
104     }
105 }