Skip to content

Commit 624a8f3

Browse files
committed
websocket encoder: cleanup - make relevant methods final
1 parent 32de987 commit 624a8f3

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

netty-websocket-http1/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketMaskedEncoder.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static class FrameFactory
105105

106106
static final WebSocketFrameFactory INSTANCE = new FrameFactory();
107107

108-
ByteBuf createDataFrame(
108+
final ByteBuf createDataFrame(
109109
ByteBufAllocator allocator, int payloadSize, int prefixSmall, int prefixMedium) {
110110
int mask = mask();
111111
if (payloadSize <= 125) {
@@ -125,35 +125,35 @@ ByteBuf createDataFrame(
125125
}
126126

127127
@Override
128-
public ByteBuf createBinaryFrame(ByteBufAllocator allocator, int payloadSize) {
128+
public final ByteBuf createBinaryFrame(ByteBufAllocator allocator, int payloadSize) {
129129
return createDataFrame(allocator, payloadSize, BINARY_FRAME_SMALL, BINARY_FRAME_MEDIUM);
130130
}
131131

132132
@Override
133-
public ByteBuf createTextFrame(ByteBufAllocator allocator, int payloadSize) {
133+
public final ByteBuf createTextFrame(ByteBufAllocator allocator, int payloadSize) {
134134
return createDataFrame(allocator, payloadSize, TEXT_FRAME_SMALL, TEXT_FRAME_MEDIUM);
135135
}
136136

137137
@Override
138-
public ByteBuf createBinaryFragmentStart(ByteBufAllocator allocator, int binaryDataSize) {
138+
public final ByteBuf createBinaryFragmentStart(ByteBufAllocator allocator, int binaryDataSize) {
139139
return createDataFrame(
140140
allocator, binaryDataSize, BINARY_FRAGMENT_START_SMALL, BINARY_FRAGMENT_START_MEDIUM);
141141
}
142142

143143
@Override
144-
public ByteBuf createTextFragmentStart(ByteBufAllocator allocator, int textDataSize) {
144+
public final ByteBuf createTextFragmentStart(ByteBufAllocator allocator, int textDataSize) {
145145
return createDataFrame(
146146
allocator, textDataSize, TEXT_FRAGMENT_START_SMALL, TEXT_FRAGMENT_START_MEDIUM);
147147
}
148148

149149
@Override
150-
public ByteBuf createContinuationFragment(ByteBufAllocator allocator, int dataSize) {
150+
public final ByteBuf createContinuationFragment(ByteBufAllocator allocator, int dataSize) {
151151
return createDataFrame(
152152
allocator, dataSize, DATA_FRAGMENT_CONTINUATION_SMALL, DATA_FRAGMENT_CONTINUATION_MEDIUM);
153153
}
154154

155155
@Override
156-
public ByteBuf createContinuationFragmentEnd(ByteBufAllocator allocator, int dataSize) {
156+
public final ByteBuf createContinuationFragmentEnd(ByteBufAllocator allocator, int dataSize) {
157157
return createDataFrame(
158158
allocator,
159159
dataSize,
@@ -162,7 +162,8 @@ public ByteBuf createContinuationFragmentEnd(ByteBufAllocator allocator, int dat
162162
}
163163

164164
@Override
165-
public ByteBuf createCloseFrame(ByteBufAllocator allocator, int statusCode, String reason) {
165+
public final ByteBuf createCloseFrame(
166+
ByteBufAllocator allocator, int statusCode, String reason) {
166167
if (!WebSocketCloseStatus.isValidStatusCode(statusCode)) {
167168
throw new IllegalArgumentException("incorrect close status code: " + statusCode);
168169
}
@@ -188,7 +189,7 @@ public ByteBuf createCloseFrame(ByteBufAllocator allocator, int statusCode, Stri
188189
}
189190

190191
@Override
191-
public ByteBuf createPingFrame(ByteBufAllocator allocator, int payloadSize) {
192+
public final ByteBuf createPingFrame(ByteBufAllocator allocator, int payloadSize) {
192193
if (payloadSize <= 125) {
193194
int mask = mask();
194195
return allocator
@@ -201,7 +202,7 @@ public ByteBuf createPingFrame(ByteBufAllocator allocator, int payloadSize) {
201202
}
202203

203204
@Override
204-
public ByteBuf createPongFrame(ByteBufAllocator allocator, int payloadSize) {
205+
public final ByteBuf createPongFrame(ByteBufAllocator allocator, int payloadSize) {
205206
if (payloadSize <= 125) {
206207
int mask = mask();
207208
return allocator
@@ -214,7 +215,7 @@ public ByteBuf createPongFrame(ByteBufAllocator allocator, int payloadSize) {
214215
}
215216

216217
@Override
217-
public ByteBuf mask(ByteBuf frame) {
218+
public final ByteBuf mask(ByteBuf frame) {
218219
int maskIndex = frame.readerIndex();
219220
int mask = frame.getInt(maskIndex);
220221
mask(mask, frame, maskIndex + /*mask size*/ 4, frame.writerIndex());
@@ -236,46 +237,46 @@ public BulkEncoder bulkEncoder() {
236237
}
237238

238239
@Override
239-
public ByteBuf encodeBinaryFrame(ByteBuf binaryFrame) {
240+
public final ByteBuf encodeBinaryFrame(ByteBuf binaryFrame) {
240241
return encodeDataFrame(binaryFrame, BINARY_FRAME_SMALL, BINARY_FRAME_MEDIUM);
241242
}
242243

243244
@Override
244-
public ByteBuf encodeTextFrame(ByteBuf textFrame) {
245+
public final ByteBuf encodeTextFrame(ByteBuf textFrame) {
245246
return encodeDataFrame(textFrame, TEXT_FRAME_SMALL, TEXT_FRAME_MEDIUM);
246247
}
247248

248249
@Override
249-
public ByteBuf encodeBinaryFragmentStart(ByteBuf fragmentFrame) {
250+
public final ByteBuf encodeBinaryFragmentStart(ByteBuf fragmentFrame) {
250251
return encodeDataFrame(
251252
fragmentFrame, BINARY_FRAGMENT_START_SMALL, BINARY_FRAGMENT_START_MEDIUM);
252253
}
253254

254255
@Override
255-
public ByteBuf encodeTextFragmentStart(ByteBuf fragmentFrame) {
256+
public final ByteBuf encodeTextFragmentStart(ByteBuf fragmentFrame) {
256257
return encodeDataFrame(fragmentFrame, TEXT_FRAGMENT_START_SMALL, TEXT_FRAGMENT_START_MEDIUM);
257258
}
258259

259260
@Override
260-
public ByteBuf encodeContinuationFragment(ByteBuf fragmentFrame) {
261+
public final ByteBuf encodeContinuationFragment(ByteBuf fragmentFrame) {
261262
return encodeDataFrame(
262263
fragmentFrame, DATA_FRAGMENT_CONTINUATION_SMALL, DATA_FRAGMENT_CONTINUATION_MEDIUM);
263264
}
264265

265266
@Override
266-
public ByteBuf encodeContinuationFragmentEnd(ByteBuf fragmentFrame) {
267+
public final ByteBuf encodeContinuationFragmentEnd(ByteBuf fragmentFrame) {
267268
return encodeDataFrame(
268269
fragmentFrame,
269270
DATA_FRAGMENT_CONTINUATION_END_SMALL,
270271
DATA_FRAGMENT_CONTINUATION_END_MEDIUM);
271272
}
272273

273274
@Override
274-
public int sizeofFragment(int payloadSize) {
275+
public final int sizeofFragment(int payloadSize) {
275276
return sizeOfDataFrame(payloadSize);
276277
}
277278

278-
ByteBuf encodeDataFrame(ByteBuf binaryFrame, int prefixSmall, int prefixMedium) {
279+
final ByteBuf encodeDataFrame(ByteBuf binaryFrame, int prefixSmall, int prefixMedium) {
279280
int frameSize = binaryFrame.readableBytes();
280281
int smallPrefixSize = 6;
281282
if (frameSize <= 125 + smallPrefixSize) {
@@ -298,16 +299,17 @@ ByteBuf encodeDataFrame(ByteBuf binaryFrame, int prefixSmall, int prefixMedium)
298299
}
299300

300301
@Override
301-
public int encodeBinaryFramePrefix(ByteBuf byteBuf, int payloadSize) {
302+
public final int encodeBinaryFramePrefix(ByteBuf byteBuf, int payloadSize) {
302303
return encodeDataFramePrefix(byteBuf, payloadSize, BINARY_FRAME_SMALL, BINARY_FRAME_MEDIUM);
303304
}
304305

305306
@Override
306-
public int encodeTextFramePrefix(ByteBuf byteBuf, int textPayloadSize) {
307+
public final int encodeTextFramePrefix(ByteBuf byteBuf, int textPayloadSize) {
307308
return encodeDataFramePrefix(byteBuf, textPayloadSize, TEXT_FRAME_SMALL, TEXT_FRAME_MEDIUM);
308309
}
309310

310-
int encodeDataFramePrefix(ByteBuf byteBuf, int payloadSize, int prefixSmall, int prefixMedium) {
311+
final int encodeDataFramePrefix(
312+
ByteBuf byteBuf, int payloadSize, int prefixSmall, int prefixMedium) {
311313
if (payloadSize <= 125) {
312314
int mask = mask();
313315
byteBuf.writeShort(prefixSmall | payloadSize);
@@ -324,12 +326,12 @@ int encodeDataFramePrefix(ByteBuf byteBuf, int payloadSize, int prefixSmall, int
324326
}
325327

326328
@Override
327-
public ByteBuf maskBinaryFrame(ByteBuf byteBuf, int mask, int payloadSize) {
329+
public final ByteBuf maskBinaryFrame(ByteBuf byteBuf, int mask, int payloadSize) {
328330
return maskDataFrame(byteBuf, mask, payloadSize);
329331
}
330332

331333
@Override
332-
public ByteBuf maskTextFrame(ByteBuf byteBuf, int mask, int textPayloadSize) {
334+
public final ByteBuf maskTextFrame(ByteBuf byteBuf, int mask, int textPayloadSize) {
333335
return maskDataFrame(byteBuf, mask, textPayloadSize);
334336
}
335337

@@ -340,12 +342,12 @@ static ByteBuf maskDataFrame(ByteBuf byteBuf, int mask, int payloadSize) {
340342
}
341343

342344
@Override
343-
public int sizeofBinaryFrame(int payloadSize) {
345+
public final int sizeofBinaryFrame(int payloadSize) {
344346
return sizeOfDataFrame(payloadSize);
345347
}
346348

347349
@Override
348-
public int sizeofTextFrame(int textPayloadSize) {
350+
public final int sizeofTextFrame(int textPayloadSize) {
349351
return sizeOfDataFrame(textPayloadSize);
350352
}
351353

netty-websocket-http1/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketNonMaskedEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public WebSocketFrameFactory frameFactory(ChannelHandlerContext ctx) {
4848
return FrameFactory.INSTANCE;
4949
}
5050

51-
static class FrameFactory
51+
static final class FrameFactory
5252
implements WebSocketFrameFactory,
5353
WebSocketFrameFactory.Encoder,
5454
WebSocketFrameFactory.BulkEncoder {

0 commit comments

Comments
 (0)