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          this(command, content, null);
35      }
36  
37      DefaultStompFrame(StompCommand command, ByteBuf content, DefaultStompHeaders headers) {
38          super(command, headers);
39  
40          if (content == null) {
41              throw new NullPointerException("content");
42          }
43  
44          this.content = content;
45      }
46  
47      @Override
48      public ByteBuf content() {
49          return content;
50      }
51  
52      @Override
53      public StompFrame copy() {
54          return replace(content.copy());
55      }
56  
57      @Override
58      public StompFrame duplicate() {
59          return replace(content.duplicate());
60      }
61  
62      @Override
63      public StompFrame retainedDuplicate() {
64          return replace(content.retainedDuplicate());
65      }
66  
67      @Override
68      public StompFrame replace(ByteBuf content) {
69          return new DefaultStompFrame(command, content, headers.copy());
70      }
71  
72      @Override
73      public int refCnt() {
74          return content.refCnt();
75      }
76  
77      @Override
78      public StompFrame retain() {
79          content.retain();
80          return this;
81      }
82  
83      @Override
84      public StompFrame retain(int increment) {
85          content.retain(increment);
86          return this;
87      }
88  
89      @Override
90      public StompFrame touch() {
91          content.touch();
92          return this;
93      }
94  
95      @Override
96      public StompFrame touch(Object hint) {
97          content.touch(hint);
98          return this;
99      }
100 
101     @Override
102     public boolean release() {
103         return content.release();
104     }
105 
106     @Override
107     public boolean release(int decrement) {
108         return content.release(decrement);
109     }
110 
111     @Override
112     public String toString() {
113         return "DefaultStompFrame{" +
114             "command=" + command +
115             ", headers=" + headers +
116             ", content=" + content.toString(CharsetUtil.UTF_8) +
117             '}';
118     }
119 }