查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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    *   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.memcache;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.util.internal.ObjectUtil;
20  import io.netty.util.internal.StringUtil;
21  import io.netty.util.internal.UnstableApi;
22  
23  /**
24   * The default {@link MemcacheContent} implementation.
25   */
26  @UnstableApi
27  public class DefaultMemcacheContent extends AbstractMemcacheObject implements MemcacheContent {
28  
29      private final ByteBuf content;
30  
31      /**
32       * Creates a new instance with the specified content.
33       */
34      public DefaultMemcacheContent(ByteBuf content) {
35          this.content = ObjectUtil.checkNotNull(content, "content");
36      }
37  
38      @Override
39      public ByteBuf content() {
40          return content;
41      }
42  
43      @Override
44      public MemcacheContent copy() {
45          return replace(content.copy());
46      }
47  
48      @Override
49      public MemcacheContent duplicate() {
50          return replace(content.duplicate());
51      }
52  
53      @Override
54      public MemcacheContent retainedDuplicate() {
55          return replace(content.retainedDuplicate());
56      }
57  
58      @Override
59      public MemcacheContent replace(ByteBuf content) {
60          return new DefaultMemcacheContent(content);
61      }
62  
63      @Override
64      public MemcacheContent retain() {
65          super.retain();
66          return this;
67      }
68  
69      @Override
70      public MemcacheContent retain(int increment) {
71          super.retain(increment);
72          return this;
73      }
74  
75      @Override
76      public MemcacheContent touch() {
77          super.touch();
78          return this;
79      }
80  
81      @Override
82      public MemcacheContent touch(Object hint) {
83          content.touch(hint);
84          return this;
85      }
86  
87      @Override
88      protected void deallocate() {
89          content.release();
90      }
91  
92      @Override
93      public String toString() {
94          return StringUtil.simpleClassName(this) +
95                 "(data: " + content() + ", decoderResult: " + decoderResult() + ')';
96      }
97  }