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