View Javadoc
1   /*
2    * Copyright 2014 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.stomp;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.Unpooled;
20  import io.netty.util.CharsetUtil;
21  
22  /**
23   * Default implementation of {@link StompFrame}.
24   */
25  public class DefaultStompFrame extends DefaultStompHeadersSubframe implements StompFrame {
26  
27      private final ByteBuf content;
28  
29      public DefaultStompFrame(StompCommand command) {
30          this(command, Unpooled.buffer(0));
31      }
32  
33      public DefaultStompFrame(StompCommand command, ByteBuf content) {
34          super(command);
35          if (content == null) {
36              throw new NullPointerException("content");
37          }
38          this.content = content;
39      }
40  
41      @Override
42      public ByteBuf content() {
43          return content;
44      }
45  
46      @Override
47      public StompFrame copy() {
48          return replace(content.copy());
49      }
50  
51      @Override
52      public StompFrame duplicate() {
53          return replace(content.duplicate());
54      }
55  
56      @Override
57      public StompFrame retainedDuplicate() {
58          return replace(content.retainedDuplicate());
59      }
60  
61      @Override
62      public StompFrame replace(ByteBuf content) {
63          return new DefaultStompFrame(command, content);
64      }
65  
66      @Override
67      public int refCnt() {
68          return content.refCnt();
69      }
70  
71      @Override
72      public StompFrame retain() {
73          content.retain();
74          return this;
75      }
76  
77      @Override
78      public StompFrame retain(int increment) {
79          content.retain(increment);
80          return this;
81      }
82  
83      @Override
84      public StompFrame touch() {
85          content.touch();
86          return this;
87      }
88  
89      @Override
90      public StompFrame touch(Object hint) {
91          content.touch(hint);
92          return this;
93      }
94  
95      @Override
96      public boolean release() {
97          return content.release();
98      }
99  
100     @Override
101     public boolean release(int decrement) {
102         return content.release(decrement);
103     }
104 
105     @Override
106     public String toString() {
107         return "DefaultStompFrame{" +
108             "command=" + command +
109             ", headers=" + headers +
110             ", content=" + content.toString(CharsetUtil.UTF_8) +
111             '}';
112     }
113 }