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 new DefaultStompFrame(command, content.copy());
49      }
50  
51      @Override
52      public StompFrame duplicate() {
53          return new DefaultStompFrame(command, content.duplicate());
54      }
55  
56      @Override
57      public int refCnt() {
58          return content.refCnt();
59      }
60  
61      @Override
62      public StompFrame retain() {
63          content.retain();
64          return this;
65      }
66  
67      @Override
68      public StompFrame retain(int increment) {
69          content.retain();
70          return this;
71      }
72  
73      @Override
74      public StompFrame touch() {
75          content.touch();
76          return this;
77      }
78  
79      @Override
80      public StompFrame touch(Object hint) {
81          content.touch(hint);
82          return this;
83      }
84  
85      @Override
86      public boolean release() {
87          return content.release();
88      }
89  
90      @Override
91      public boolean release(int decrement) {
92          return content.release(decrement);
93      }
94  
95      @Override
96      public String toString() {
97          return "DefaultFullStompFrame{" +
98              "command=" + command +
99              ", headers=" + headers +
100             ", content=" + content.toString(CharsetUtil.UTF_8) +
101             '}';
102     }
103 }