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