View Javadoc

1   /*
2    * Copyright 2012 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.http.websocketx;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.DefaultByteBufHolder;
20  import io.netty.util.internal.StringUtil;
21  
22  /**
23   * Base class for web socket frames
24   */
25  public abstract class WebSocketFrame extends DefaultByteBufHolder {
26  
27      /**
28       * Flag to indicate if this frame is the final fragment in a message. The first fragment (frame) may also be the
29       * final fragment.
30       */
31      private final boolean finalFragment;
32  
33      /**
34       * RSV1, RSV2, RSV3 used for extensions
35       */
36      private final int rsv;
37  
38      protected WebSocketFrame(ByteBuf binaryData) {
39          this(true, 0, binaryData);
40      }
41  
42      protected WebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
43          super(binaryData);
44          this.finalFragment = finalFragment;
45          this.rsv = rsv;
46      }
47  
48      /**
49       * Flag to indicate if this frame is the final fragment in a message. The first fragment (frame) may also be the
50       * final fragment.
51       */
52      public boolean isFinalFragment() {
53          return finalFragment;
54      }
55  
56      /**
57       * Bits used for extensions to the standard.
58       */
59      public int rsv() {
60          return rsv;
61      }
62  
63      @Override
64      public abstract WebSocketFrame copy();
65  
66      @Override
67      public abstract WebSocketFrame duplicate();
68  
69      @Override
70      public String toString() {
71          return StringUtil.simpleClassName(this) + "(data: " + contentToString() + ')';
72      }
73  
74      @Override
75      public WebSocketFrame retain() {
76          super.retain();
77          return this;
78      }
79  
80      @Override
81      public WebSocketFrame retain(int increment) {
82          super.retain(increment);
83          return this;
84      }
85  }