查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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    *   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.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 WebSocketFrame copy() {
65          return (WebSocketFrame) super.copy();
66      }
67  
68      @Override
69      public WebSocketFrame duplicate() {
70          return (WebSocketFrame) super.duplicate();
71      }
72  
73      @Override
74      public WebSocketFrame retainedDuplicate() {
75          return (WebSocketFrame) super.retainedDuplicate();
76      }
77  
78      @Override
79      public abstract WebSocketFrame replace(ByteBuf content);
80  
81      @Override
82      public String toString() {
83          return StringUtil.simpleClassName(this) + "(data: " + contentToString() + ')';
84      }
85  
86      @Override
87      public WebSocketFrame retain() {
88          super.retain();
89          return this;
90      }
91  
92      @Override
93      public WebSocketFrame retain(int increment) {
94          super.retain(increment);
95          return this;
96      }
97  
98      @Override
99      public WebSocketFrame touch() {
100         super.touch();
101         return this;
102     }
103 
104     @Override
105     public WebSocketFrame touch(Object hint) {
106         super.touch(hint);
107         return this;
108     }
109 }