1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http.websocketx;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
20 import io.netty.util.CharsetUtil;
21
22
23
24
25 public class TextWebSocketFrame extends WebSocketFrame {
26
27
28
29
30 public TextWebSocketFrame() {
31 super(Unpooled.buffer(0));
32 }
33
34
35
36
37
38
39
40 public TextWebSocketFrame(String text) {
41 super(fromText(text));
42 }
43
44
45
46
47
48
49
50 public TextWebSocketFrame(ByteBuf binaryData) {
51 super(binaryData);
52 }
53
54
55
56
57
58
59
60
61
62
63
64 public TextWebSocketFrame(boolean finalFragment, int rsv, String text) {
65 super(finalFragment, rsv, fromText(text));
66 }
67
68 private static ByteBuf fromText(String text) {
69 if (text == null || text.isEmpty()) {
70 return Unpooled.EMPTY_BUFFER;
71 } else {
72 return Unpooled.copiedBuffer(text, CharsetUtil.UTF_8);
73 }
74 }
75
76
77
78
79
80
81
82
83
84
85
86 public TextWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
87 super(finalFragment, rsv, binaryData);
88 }
89
90
91
92
93 public String text() {
94 return content().toString(CharsetUtil.UTF_8);
95 }
96
97 @Override
98 public TextWebSocketFrame copy() {
99 return (TextWebSocketFrame) super.copy();
100 }
101
102 @Override
103 public TextWebSocketFrame duplicate() {
104 return (TextWebSocketFrame) super.duplicate();
105 }
106
107 @Override
108 public TextWebSocketFrame retainedDuplicate() {
109 return (TextWebSocketFrame) super.retainedDuplicate();
110 }
111
112 @Override
113 public TextWebSocketFrame replace(ByteBuf content) {
114 return new TextWebSocketFrame(isFinalFragment(), rsv(), content);
115 }
116
117 @Override
118 public TextWebSocketFrame retain() {
119 super.retain();
120 return this;
121 }
122
123 @Override
124 public TextWebSocketFrame retain(int increment) {
125 super.retain(increment);
126 return this;
127 }
128
129 @Override
130 public TextWebSocketFrame touch() {
131 super.touch();
132 return this;
133 }
134
135 @Override
136 public TextWebSocketFrame touch(Object hint) {
137 super.touch(hint);
138 return this;
139 }
140 }