1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.http.websocket;
17
18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.buffer.ChannelBuffers;
20 import org.jboss.netty.util.CharsetUtil;
21
22
23
24
25
26
27 @Deprecated
28 public class DefaultWebSocketFrame implements WebSocketFrame {
29
30 private int type;
31 private ChannelBuffer binaryData;
32
33
34
35
36 public DefaultWebSocketFrame() {
37 this(0, ChannelBuffers.EMPTY_BUFFER);
38 }
39
40
41
42
43 public DefaultWebSocketFrame(String textData) {
44 this(0, ChannelBuffers.copiedBuffer(textData, CharsetUtil.UTF_8));
45 }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public DefaultWebSocketFrame(int type, ChannelBuffer binaryData) {
61 setData(type, binaryData);
62 }
63
64 public int getType() {
65 return type;
66 }
67
68 public boolean isText() {
69 return (getType() & 0x80) == 0;
70 }
71
72 public boolean isBinary() {
73 return !isText();
74 }
75
76 public ChannelBuffer getBinaryData() {
77 return binaryData;
78 }
79
80 public String getTextData() {
81 return getBinaryData().toString(CharsetUtil.UTF_8);
82 }
83
84 public void setData(int type, ChannelBuffer binaryData) {
85 if (binaryData == null) {
86 throw new NullPointerException("binaryData");
87 }
88
89 if ((type & 0x80) == 0) {
90
91 int delimPos = binaryData.indexOf(
92 binaryData.readerIndex(), binaryData.writerIndex(), (byte) 0xFF);
93 if (delimPos >= 0) {
94 throw new IllegalArgumentException(
95 "a text frame should not contain 0xFF.");
96 }
97 }
98
99 this.type = type & 0xFF;
100 this.binaryData = binaryData;
101 }
102
103 @Override
104 public String toString() {
105 return getClass().getSimpleName() +
106 "(type: " + getType() + ", " + "data: " + getBinaryData() + ')';
107 }
108 }