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 replace(content.copy());
46      }
47  
48      @Override
49      public HttpContent duplicate() {
50          return replace(content.duplicate());
51      }
52  
53      @Override
54      public HttpContent retainedDuplicate() {
55          return replace(content.retainedDuplicate());
56      }
57  
58      @Override
59      public HttpContent replace(ByteBuf content) {
60          return new DefaultHttpContent(content);
61      }
62  
63      @Override
64      public int refCnt() {
65          return content.refCnt();
66      }
67  
68      @Override
69      public HttpContent retain() {
70          content.retain();
71          return this;
72      }
73  
74      @Override
75      public HttpContent retain(int increment) {
76          content.retain(increment);
77          return this;
78      }
79  
80      @Override
81      public HttpContent touch() {
82          content.touch();
83          return this;
84      }
85  
86      @Override
87      public HttpContent touch(Object hint) {
88          content.touch(hint);
89          return this;
90      }
91  
92      @Override
93      public boolean release() {
94          return content.release();
95      }
96  
97      @Override
98      public boolean release(int decrement) {
99          return content.release(decrement);
100     }
101 
102     @Override
103     public String toString() {
104         return StringUtil.simpleClassName(this) +
105                "(data: " + content() + ", decoderResult: " + decoderResult() + ')';
106     }
107 }